1. наследовать С2 от TPersistent
2. переопределить метод Assign в С2
3. использовать в дальнейшем Assign
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TC2 = class(TPersistent)
public
SProp: String;
IProp: Integer;
procedure Assign(Source: TPersistent); override;
end;
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TC2 }
procedure TC2.Assign(Source: TPersistent);
begin
SProp:=TC2(Source).SProp;
IProp:=TC2(Source).IProp;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
c21: TC2;
c22: TC2;
begin
c21:=TC2.Create;
c22:=TC2.Create;
c21.SProp:='hello world';
c21.IProp:=255;
c22.Assign(c21);
c21.Free;
ShowMessage(c22.SProp+' '+IntToStr(c22.IProp));
c22.Free;
end;
end.