Description |
The TObject type defines the base class type. It is the oldest grandparent of all classes - every class is ultimately derived from TObject.
Because of this, every object inherits the methods of TObject.
The TObject methods fall into two categories - class and non-class. When prefixed by the keyword Class, a method may be called in both an object of the class, and in the class itself. Such a static method cannot access any class fields because a class has no data itself - only instantiated classes - objects - have data.
Some key Class (static) methods:
function ClassName | Gives the class name as a string |
ClassParent | Gives the class parent name |
ClassInfo | Gives class Run Time info |
InstanceSize | Size of class object in bytes |
NewInstance | Creates a new class object |
Some key Object methods:
Create | Empty object creator |
Free | Calls Destroy for a non-nil object ref |
Destroy | Releases object storage |
AfterConstruction | Called after construction |
BeforeDestruction | Called before destruction |
|
|
Related commands |
Class |
|
Starts the declaration of a type of object class |
Printer |
|
Returns a reference to the global Printer object |
|
|
|
Example code : Using TObject methods inherited in a TForm subclass |
begin // The unit form was derived from TObject. // So we can use methods of TObject:
ShowMessage('Form1 object class name = '+
Form1.ClassName);
ShowMessage('Form1 object class parent name = '+
Form1.ClassParent.ClassName);
ShowMessage('Form1 object instance size = '+
IntToStr(Form1.InstanceSize));
// And now on TObject itself
ShowMessage('TObject class name = '+
TObject.ClassName);
ShowMessage('TObject instance size = '+
IntToStr(TObject.InstanceSize));
end;
|
Show full unit code |
Form1 object class name = TForm1
Form1 object parent class name = TForm
Form1 object instance size = 764
TObject class name = TObject
TObject instance size = 4
|
|