[Overview][Constants][Types][Classes][Procedures and functions][Variables] Reference for unit 'Classes' (#rtl)

TPersistent.Assign

Assign the contents of one class to another.

Declaration

Source position: classesh.inc line 304

public procedure TPersistent.Assign(

  Source: TPersistent

); virtual;

Description

Assigncopies the contents of Sourceto Self, if the classes of the destination and source classes are compatible.

The TPersistentimplementation of Assigndoes nothing but calling the AssignTomethod of source. This means that if the destination class does not know how to assign the contents of the source class, the source class instance is asked to assign itself to the destination class. This means that it is necessary to implement only one of the two methods so that two classes can be assiged to one another.

Remark:

In general, a statement of the form

Destination:=Source;

(where Destinationand Sourceare classes) does not achieve the same as a statement of the form

Destination.Assign(Source);

After the former statement, both Sourceand Destinationwill point to the same object. The latter statemtent will copy the contentsof the Sourceclass to the Destinationclass.

See also

AssignTo

  

Generic assignment function.