[fpc-pascal]Classes and copying
Michael Van Canneyt
michael.vancanneyt at wisa.be
Wed Feb 12 12:19:33 CET 2003
On Wed, 12 Feb 2003, James Mills wrote:
> Hi all,
>
> With respect to classes (and perhaps also objects), how do you copy the
> contents of a class in memory (an object) to another?
>
> ie:
>
> var
> a: TClass;
> b: TClass;
>
> begin
> a := TClass.init;
> b := a; //This only copies the pointer and doesn't work ??
> end.
>
This indeed only copies the pointer. if you want to do more than that,
then you need to implement this yourself.
TPersistent implements the 'Assign' method for this. You can create a
descendent from TPersistent, override the Assign method, and then
copy fields as necessary in the new Assign method.
Michael.
More information about the fpc-pascal
mailing list