Probiers halt aus. Variante wäre direkt mit TGraphicObjectClass zu arbeiten, das geht. Dann kann aber nicht mehr Is Typ1,2,3 abfragen.
So getestet:
Delphi-Quellcode:
TObject0 =
class
private
FA: integer;
FB: integer;
FC: integer;
public
property A: integer
read FA
write FA;
property B: integer
read FB write FB;
property C: integer
read FC
write FC;
procedure Assign(Value: TObject0);
virtual;
end;
TObject1 =
class(TObject0)
private
FSL: TStringList;
public
property SL: TStringList
read FSL;
procedure Assign(Value: TObject0);
override;
constructor Create;
destructor Destroy;
override;
end;
{ TObject0 }
procedure TObject0.Assign(Value: TObject0);
begin
FA := Value.A;
FB := Value.B;
FC := Value.C;
end;
{ TObject1 }
procedure TObject1.Assign(Value: TObject0);
var
O: TObject1;
begin
inherited;
O := TObject1(Value);
FSL.Assign(O.SL);
end;
constructor TObject1.Create;
begin
inherited;
FSL := TStringList.Create;
end;
destructor TObject1.Destroy;
begin
FSL.Free;
inherited;
end;
procedure TTestForm.Button1Click(Sender: TObject);
type
TObjectClass =
class of TObject0;
var
A: TObject1;
B: TObject0;
begin
A := TObject1.Create;
try
B := TObjectClass(A.ClassType).Create;
try
B.Assign(A);
finally
B.Free;
end;
finally
A.Free;
end;
end;