|
Dave,
as strange as it may seem, you are not far off. The
pattern that is used widely in the VCL is having an Assign method. For
example
TAnimal = class(TObject)
procedure Assign(Source :
TObject); virtual;
property LegCount
etc
property Colour etc
end;
TDog = class(TAnimal)
procedure Assign(Source :
TObject); override;
property BarkDB etc
property Breed etc
end;
....
procedure TAnimal.Assign(Source :
TObject);
begin
if Source is TAnimal then
begin
LegCount :=
TAnimal(Source).LegCount;
Colour :=
TAnimal(Source).LegCount;
end
else
raise some kind of
exception
end;
procedure TDog.Assign(Source :
TObject);
begin
inherited Assign(Source);
if Source is TDog then
begin
BarkDB :=
TDog(Source).BarkDB;
Breed :=
TDog(Source).Bark.DB;
end
else
raise some kind of
exception
end;
You could try using a generic RTTI routine but
these can get messy, hard to read later, and outdated by changed in the
compiler.
Phil.
|
- [DUG]: How do I copy the state of one object to another? Dave . Jollie
- Re: [DUG]: How do I copy the state of one object to ... Neven MacEwan
- Re: [DUG]: How do I copy the state of one object to ... ping_delphilist
- RE: [DUG]: How do I copy the state of one object to ... Phil Middlemiss
- RE: [DUG]: How do I copy the state of one object to ... Conor.Boyd
- RE: [DUG]: How do I copy the state of one object to ... Dave . Jollie
