RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TPersistent.AssignTo Method

Copies the properties of an object to a destination object.

Pascal
procedure AssignTo(Dest: TPersistent); virtual;
C++
virtual __fastcall AssignTo(TPersistent * Dest);

Override the AssignTo method to extend the functionality of the Assign method of destination objects so that they handle newly created object classes. When defining a new object class, override the Assign method for every existing object class that should be able to copy its properties to the new class. Override the AssignTo method for every existing class to which the new class can copy. 

The Assign method of TPersistent calls AssignTo if the descendant object does not succeed in copying the properties of a source object. The AssignTo method defined by TPersistent raises an EConvertError exception.  

For example, given the following code in which A and B are instance variables:

A.Assign(B); {Delphi}

 

A->Assign(B); // C++

if A knows how to handle B, then it does so and returns. If A doesn't know how to handle B's type, execution will trickle to the TPersistent version of Assign, which calls:

B.AssignTo(A); {Delphi}

 

B->AssignTo(A); // C++

If B knows how to copy to A, the assignment succeeds. Otherwise, TPersistent raises an exception. 

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!