Object¶
Qualified name: delphivcl.Object
- class Object¶
Bases:
object
TObject is the ultimate ancestor of all objects and components. TObject encapsulates fundamental behavior common to objects by introducing methods that:
Create, maintain, and destroy instances of the object by allocating, initializing, and freeing required memory. Respond when object instances are created or destroyed. Return class-type and instance information on an object and runtime type information (RTTI) about its published properties. Support message handling. Support interfaces implemented by the object. Use TObject as an immediate base class when declaring simple objects that do not need to persist (are not saved and reloaded) and that do not need to be assigned to other objects. Much of the capability of objects is established by methods that TObject introduces. Many of these methods are used internally by IDEs and are not intended for users to call directly. Others are overridden in descendant objects that have more complex behavior. Although TObject is the based object of a component framework, not all objects are components. All component classes descend from TComponent.
Note: TObject is never directly instantiated. Although it does not use programming language features that prevent instantiation, TObject is an abstract class.
Methods
Responds after the last constructor has executed.
Responds before the first destructor executes.
Returns a pointer to the run-time type information (RTTI) table for the object type.
Determines whether an object is of a specific type.
Returns the type of the immediate ancestor of a class.
Returns the class reference for the object's class.
Performs finalization on long strings, variants, and interface variables within a class.
Provides the interface for a method that processes message records.
Calls message-handling methods for the object, based on the contents of the Message parameter.
DisposeOf forces the execution of the destructor code in an object.
Checks whether the current instance and the Obj parameter are equal.
Returns the address of a published object field.
Frees the Wrapped Delphi Object
Deallocates memory allocated by a previous call to the NewInstance method.
Returns an integer containing the hash code.
Retrieves a specified interface.
Returns the entry for a specific interface implemented in a class.
Returns a pointer to a structure containing all of the interfaces implemented by a given class.
Returns True if Delphi Object is or inherits from ClassName
Initializes a newly allocated object instance to all zeros and initializes the instance's virtual method table pointer.
Returns the size in bytes of each instance of the object type.
Returns the address of a class method by name.
Returns the name of a class method by address.
Allocates memory for an instance of an object type and returns a pointer to that new instance.
Returns the qualified name of the class.
Handles exceptions in methods declared using the safecall calling convention.
Sets several properties in one call
If the object is a container (TStrings, TComponent...), it returns the content of the sequence as a Python list object.
Returns a string containing the class name.
If the object is a container (TStrings, TComponent...), it returns the content of the sequence as a Python tuple object.
Returns the name of the unit where the class is defined.
Returns the class's unit scope.
Attributes
Returns the TObject.ClassName
- AfterConstruction()¶
Responds after the last constructor has executed. AfterConstruction is called automatically after the object’s last constructor has executed. Do not call it explicitly in your applications. The AfterConstruction method implemented in TObject does nothing. Override this method when creating a class that performs an action after the object is created. For example, TCustomForm overrides AfterConstruction to generate an OnCreate event.
- BeforeDestruction()¶
Responds before the first destructor executes. BeforeDestruction is called automatically before the object’s first destructor executes. Do not call it explicitly in your applications. The BeforeDestruction method implemented in TObject does nothing. Override this method when creating a class that performs an action before the object is destroyed. For example, TCustomForm overrides BeforeDestruction to generate an OnDestroy event.
Note: BeforeDestruction is not called when the object is destroyed before it is fully constructed. That is, if the object’s constructor raises an exception, the destructor is called to dispose of the object, but BeforeDestruction is not called.
- CPP_ABI_1()¶
- CPP_ABI_2()¶
- CPP_ABI_3()¶
- ClassInfo()¶
Returns a pointer to the run-time type information (RTTI) table for the object type. ClassInfo provides access to the RTTI table for a given object type. Some classes do not provide run-time type information. For these classes, ClassInfo returns nil (Delphi) or NULL (C++). All classes descended from TPersistent do provide run-time type information.
- ClassName¶
Returns the TObject.ClassName
- ClassNameIs(Name: str) bool ¶
Determines whether an object is of a specific type. ClassNameIs determines whether an object instance or class reference has a class name that matches a specified string. This is useful to query objects across modules or shared libraries.
Note: In C++ code, call ClassNameIs as a method to compare an object’s class name. Use the global static function to compare the class name from a metaclass object.
- ClassParent()¶
Returns the type of the immediate ancestor of a class. ClassParent returns the name of the parent class for an object instance or class reference. For TObject, ClassParent returns nil (Delphi) or NULL (C++). Avoid using ClassParent in application code.
Note: In Delphi code, use the is or as operators instead of ClassParent. Note: In C++ code, use a dynamic cast or the InheritsFrom method instead of ClassParent.
- ClassType()¶
Returns the class reference for the object’s class.
Note: ClassType dynamically determines the type of an object and returns its class reference, or metaclass. Avoid using ClassType in application code.
Note: In Delphi code, use the is or as operators instead of ClassType. Note: In C++ code, use a dynamic cast or the InheritsFrom method instead of ClassType.
- CleanupInstance()¶
Performs finalization on long strings, variants, and interface variables within a class. Do not call CleanupInstance directly. CleanupInstance is called automatically when the object instance is destroyed. CleanupInstance releases all long strings and variants. It sets long strings to empty and variants to Unassigned.
- DefaultHandler(Message) None ¶
Provides the interface for a method that processes message records. DefaultHandler is called by Dispatch when it cannot find a method for a particular message. DefaultHandler provides message handling for all messages for which an object does not have specific handlers. Descendant classes that process messages override DefaultHandler according to the types of messages they handle.
Note: In a Delphi message-handling method, calling inherited results in a call to the ancestor’s DefaultHandler method only if that ancestor does not specify a message method for the particular message being handled. Otherwise, calling inherited results in a call to the specific handler for that type of message.
- Dispatch(Message) None ¶
Calls message-handling methods for the object, based on the contents of the Message parameter. Call Dispatch to automatically pass messages to the appropriate message handler. Dispatch determines whether a message is in the list of message handlers declared for the object. If the object does not handle the message, Dispatch then examines the message-handler list of the ancestor class, and continues checking ancestors until it either finds a specific handler or runs out of ancestors, in which case it calls DefaultHandler. The only assumption Dispatch makes about the data in Message is that the first two bytes contain a message ID�that is, an integer that determines which message handler Dispatch calls. Although any kind of data can be passed to Dispatch, most TObject descendants expect a message record such as TMessage or a specific data structure type.
- DisposeOf()¶
DisposeOf forces the execution of the destructor code in an object. It was an artifact from previous versions when the Delphi Mobile compilers supported Automatic Reference Counting. In current versions of Delphi, DisposeOf is used as a wrapper that invokes TObject.Free.
- type
TMySimpleClass = class private
stringMember: String; constructor Create(const Text: String); destructor Destroy;
end;
constructor TMySimpleClass.Create(const Text: String); begin
stringMember := Text;
end;
destructor TMySimpleClass.Destroy; begin
// this will be executed on calling the DisposeOf method.
end;
- var
myObject: TMySimpleClass;
- begin
myObject := TMySimpleClass.Create(‘This is a code snippet indicating the usage of the DisposeOf method’); try
// Use ‘myObject’ here
- finally
myObject.DisposeOf;
end;
end.
- Equals(Obj: Object) bool ¶
Checks whether the current instance and the Obj parameter are equal. The function has one Obj parameter of the TObject type. By default, the Equals method shows whether the addresses corresponding to the current object and the Obj object are identical. The method returns a boolean value that represents the equality between the two addresses.
Note: Equals is supposed to be overridden in user-derived classes, to provide consumer objects with an equality determining function. For example, in the FMX.Types.TBounds class, Equals also returns True if the Rect properties of the current object and of the Obj object are equal. In the FMX.StdActns.TBaseValueRange class, Equals also returns True if all the properties of the current object and of the Obj object are equal.
- FieldAddress(Name: str) Pointer ¶
Returns the address of a published object field. FieldAddress is used internally by the component streaming system to access a specified published field of an object. FieldAddress returns a pointer to the field, if it exists. If the object has no published field by that name, FieldAddress returns nil (Delphi) or NULL (C++). Programs should access and manipulate fields by using properties instead of FieldAddress. Returns the address of a published object field. FieldAddress is used internally by the component streaming system to access a specified published field of an object. FieldAddress returns a pointer to the field, if it exists. If the object has no published field by that name, FieldAddress returns nil (Delphi) or NULL (C++). Programs should access and manipulate fields by using properties instead of FieldAddress.
- Free()¶
Frees the Wrapped Delphi Object
- FreeInstance()¶
Deallocates memory allocated by a previous call to the NewInstance method. All destructors call FreeInstance automatically to deallocate memory that was allocated by overriding NewInstance. Do not call FreeInstance directly. FreeInstance should be overridden if NewInstance was overridden to change the way the object’s instance data was allocated. Like NewInstance, FreeInstance uses the value returned from InstanceSize to deallocate the object’s memory.
- GetHashCode()¶
Returns an integer containing the hash code. By default, calling GetHashCode on an object returns an integer representing the virtual address at which the object is stored.
Notes: GetHashCode is supposed to be overridden in user-derived classes, to provide consumer objects with an integer hash code representation. The sign of the hash code depends on the address of the particular object instance. Negative hash code can appear for object instances that reside at higher memory locations.
- GetInterface(IID: GUID, Obj) bool ¶
Retrieves a specified interface. GetInterface retrieves the interface designated by a GUID or type name. The basic implementation of GetInterface uses the GUID specified in the IID parameter. If the specified interface is supported by the class, it is returned in the Obj parameter, and GetInterface has a return value of True. Otherwise, Obj contains nil (Delphi) or NULL (C++), and GetInterface returns False.
Note: In Delphi code, IID can be an interface name. The compiler automatically translates this name into the corresponding GUID. Note: In C++ code, use the templated version of GetInterface to obtain an interface from a DelphiInterface object. GetInterface is equivalent to the as operator (Delphi) and dynamic casts (C++), except that GetInterface does not raise an exception if the interface is not supported.
- GetInterfaceEntry(IID: GUID) PInterfaceEntry ¶
Returns the entry for a specific interface implemented in a class. GetInterfaceEntry returns the class entry for the interface specified by the IID parameter.
Note: In Delphi Code, IID can be an interface name. The compiler replaces this name with the actual GUID. Note: COM objects can use GetInterfaceEntry to automate dispatch calls to a dual-IDispatch interface.
- GetInterfaceTable()¶
Returns a pointer to a structure containing all of the interfaces implemented by a given class. GetInterfaceTable returns the interface entries for the class. This list contains only interfaces implemented by this class, not its ancestors. To find the ancestor list, iteratively call ClassParent and then call GetInterfaceTable on the value it returns. To find the entry for a specific interface, use the GetInterfaceEntry method instead.
- InheritsFrom(ClassName)¶
Returns True if Delphi Object is or inherits from ClassName
- InitInstance(Instance: Pointer) Object ¶
Initializes a newly allocated object instance to all zeros and initializes the instance’s virtual method table pointer. You should not call InitInstance directly. InitInstance is called by NewInstance when an object is created. When overriding NewInstance, be sure to call InitInstance as the last statement. InitInstance is not virtual, so you cannot override it. Instead, initialize any data for an object in the constructor.
- InstanceSize()¶
Returns the size in bytes of each instance of the object type. InstanceSize indicates how many bytes of memory are required for a class’s instance data. InstanceSize is called from methods that allocate and deallocate memory. InstanceSize is not a virtual method, so it cannot be overridden. InstanceSize should be called only when implementing a custom version of NewInstance.
- MethodAddress(Name: str) Pointer ¶
Returns the address of a class method by name.
Note: You can use MethodAddress for published methods only. There are situations when it is useful to invoke an object method without hard coding the method name in advance. Call MethodAddress to dynamically retrieve the address of such a method by specifying the method Name as a string. An easy way to invoke the method is to define a procedure or function data type, such as:
type TProc = procedure of object;
Assign the object name and the MethodAddress method to a TMethod variable, such as:
MethodVar.Data�:= Pointer(ObjectInstanceName); MethodVar.Code�:= ObjectInstanceName.MethodAddress(‘MethodNameString’);
Pass this in a call to a variable of the procedure or function type:
Proc�:= TProc(MethodVar); Proc; Returns the address of a class method by name.
Note: You can use MethodAddress for published methods only. There are situations when it is useful to invoke an object method without hard coding the method name in advance. Call MethodAddress to dynamically retrieve the address of such a method by specifying the method Name as a string. An easy way to invoke the method is to define a procedure or function data type, such as:
type TProc = procedure of object;
Assign the object name and the MethodAddress method to a TMethod variable, such as:
MethodVar.Data�:= Pointer(ObjectInstanceName); MethodVar.Code�:= ObjectInstanceName.MethodAddress(‘MethodNameString’);
Pass this in a call to a variable of the procedure or function type:
Proc�:= TProc(MethodVar); Proc;
- MethodName(Address: Pointer) str ¶
Returns the name of a class method by address. There are situations when it is useful to invoke an object method without hard coding the method name in advance. Call MethodAddress to dynamically retrieve the address of such a method by specifying the method name as a string. MethodName is the opposite of this process–by supplying an Address method, the name of the method is returned as a string.
- NewInstance()¶
Allocates memory for an instance of an object type and returns a pointer to that new instance. All constructors call NewInstance automatically. NewInstance calls InstanceSize to determine how much memory containing a particular instance to allocate from the heap. Do not call NewInstance directly. Override NewInstance only for special memory allocation requirements. For example, when allocating a large number of identical objects that all need to be in memory at the same time, you can allocate a single block of memory for the entire group, then override NewInstance to use part of that larger block for each instance. If you override NewInstance to allocate memory, you may need to override FreeInstance to deallocate the memory.
Note: By default, NewInstance calls InitInstance.
- QualifiedClassName()¶
Returns the qualified name of the class. QualifiedClassName returns the class’s unit scope concatenated with the class name. Example:
- uses
SysUtils, SyncObjs;
- begin
Writeln(TEvent.QualifiedClassName); // displays System.SyncObjs.TEvent
- SafeCallException(ExceptObject: Object, ExceptAddr: Pointer) int ¶
Handles exceptions in methods declared using the safecall calling convention. SafeCallException handles exceptions in methods that use the safecall calling convention. Some classes that implement interfaces override this method to handle possible errors. As implemented in TObject, SafeCallException simply returns E_UNEXPECTED. This is the appropriate response for classes that do no support interfaces.
- SetProps(prop1=val1, prop2=val2...)¶
Sets several properties in one call
- ToList()¶
If the object is a container (TStrings, TComponent…), it returns the content of the sequence as a Python list object.
- ToString()¶
Returns a string containing the class name. By default, the ToString returns a string containing the class name of the instance that is being called. For example, calling ToString on a TButton instance returns a string containing “TButton”.
Note: ToString is intended to be overridden in user-derived classes, to provide consumer objects with a string representation.
- ToTuple()¶
If the object is a container (TStrings, TComponent…), it returns the content of the sequence as a Python tuple object.
- UnitName()¶
Returns the name of the unit where the class is defined. UnitName can be used to obtain the unit where a specific class is defined. For example, calling UnitName on TButton returns the Vcl.StdCtrls string.
- UnitScope()¶
Returns the class’s unit scope. The class’s unit scope is currently equivalent with the class’s unit name.
- uses
SysUtils, SyncObjs;
- begin
Writeln(TEvent.UnitScope); // displays System.SyncObjs // …