System.Classes.TPersistent.AssignTo

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

procedure AssignTo(Dest: TPersistent); virtual;

C++

virtual void __fastcall AssignTo(TPersistent* Dest);

Properties

Type Visibility Source Unit Parent
procedure
function
protected
System.Classes.pas
System.Classes.hpp
System.Classes TPersistent

Description

Copies the properties of an object to a destination object.

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.

See Also