Persistent#

Qualified name: delphivcl.Persistent

class Persistent#

Bases: Object

TPersistent is the ancestor for all objects that have assignment and streaming capabilities. TPersistent encapsulates the behavior common to all objects that can be assigned to other objects, and that can read and write their properties to and from a form file (.xfm or .dfm file). For this purpose, TPersistent introduces methods that can be overridden to:

Define the procedure for loading and storing unpublished data to a stream. Provide the means to assign values to properties. Provide the means to assign the contents of one object to another. Do not create instances of TPersistent. Use TPersistent as a base class when declaring objects that are not components, but that need to be saved to a stream or have their properties assigned to other objects.

Methods

Assign

Copies the contents of another similar object.

Destroy

Destroys the TPersistent instance and frees its memory.

GetNamePath

Returns the name of the object as it appears in the Object Inspector.

Attributes

ClassName

Returns the TObject.ClassName

Assign(Source: Persistent)#

Copies the contents of another similar object. Assign copies properties and other attributes of the specified Source object to the current object. The standard form of a call to Assign is:

Destination.Assign(Source); {Delphi}

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

which tells the current 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 cannot 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 written 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.

ClassName#

Returns the TObject.ClassName

Destroy()#

Destroys the TPersistent instance and frees its memory. Do not call Destroy directly. Call Free instead. Free checks that the object reference is not nil before calling Destroy.

GetNamePath()#

Returns the name of the object as it appears in the Object Inspector. GetNamePath is for internal use only. It determines the text that the Object Inspector displays for the name of the object being edited. GetNamePath is introduced in TPersistent so descendants such as collections can appear in the Object Inspector. Do not call GetNamePath directly. For components, GetNamePath returns the component name. For TCollectionItem objects it returns the name of the hosting component, the name of the property, and the index into the collection surrounded by brackets.