One way of doing object cloning is to design your object so that all of the
important values are exposed as properties, and to write a generic property
copying method. Then you simply create a new object of the same class as the
original object, and then copy over all of the properties. This provides for
a fairly quick and dirty cloning mechanism that relies on minimal code to
achieve. Assuming you have:

  TMyBaseObject = class(TObject)
  end;

  TMyBaseClass = class of TMyBaseObject;

then you can do the following to any decendant of TMyBaseObject:

  NewObject = TMyBaseObject(OldObject.ClassType).Create;
  CopyProperties(OldObject, NewObject);

and you'll have a cloned copy. As an excercise to the readr I'll leave
writing the copy properties procedure, and handling properties with
undesirable side effects.

Cheers, Max.


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

Reply via email to