Classes.TPersistent.Assign

From RAD Studio VCL Reference
Jump to: navigation, search

Contents

Delphi Information

From Classes.pas

	procedure Assign(Source: TPersistent); virtual;


Unit: Classes

Type: method

Visibility: public

Member Of: TPersistent

C++ Information

From Classes.hpp

	virtual void __fastcall Assign(Classes::TPersistent * Source);


Unit: Classes

Type: method

Visibility: public

Member Of: TPersistent

Description

Copies the contents of another, similar object.


Call Assign to copy the properties or other attributes of one object from another. The standard form of a call to Assign is



Destination.Assign(Source); {Delphi}



Destination->Assign(Source); // C++



which tells the Destination object to copy the contents of the Source object to itself.

Most objects override Assign to handle the assignment of properties from similar objects. When overriding Assign, call the inherited method if the destination object can't handle the assignment of properties from the class of the Source parameter.

If no overridden Assign method can handle the assignment of properties from Source, the method implemented in TPersistent calls the source object's AssignTo method. This allows the source object to handle the assignment. If the Source object is nil (Delphi) or NULL (C++), Assign raises an EConvertError exception.

In general, the statement



Destination := Source; {Delphi}



Destination = Source; // C++



is not the same as the statement



Destination.Assign(Source); {Delphi}



Destination->Assign(Source); // C++



The assignment operator makes Destination reference the same object as Source, whereas the Assign method copies the contents of the object referenced by Source into the object referenced by Destination.

Note:  The types of some properties are also objects. If these properties have write methods that use Assign to set the value of the property, then in these cases the assignment operator does the same thing as the Assign method.

See Also

Personal tools
Translations
Newest Version