Fun With TObject
TObject has some basic functionality available for all Delphi classes. Since TObject is the base class for Delphi, you should become familiar with it's features.
To see TObject in action, alter the click event of a button as follows:
var
MyObject: TObject;
begin
MyObject := TObject.Create; //Create object instance.
ShowMessage(MyObject.ClassName); //Return the class name.
ShowMessage(UnitName); //UnitName is a class function
//defined in TObject.
MyObject.Free; //Free object instance.
end;
Next, view the source code for TObject to see what routines are implemented. The easiest way to find TObject's declaration is to right click on TObject in your source code and select Find Declaration. Most of these routines are documented in the help so you can place the cursor on any procedure or function name and press F1.
Common Inheritance Choices
The following is a short list of some more common VCL classes you can inherit from.
Class |
Use For |
Features / Notes |
TObject |
demos |
create, destroy |
TPersistent |
streaming objects |
Save object
TObject >> TPersistent |
TComponent |
non-visual classes |
Ability to appear on the Component / Tool palette and to be manipulated in the Form Designer.
TObject >> TPersistent >> TComponent |
TControl |
visual classes |
Visual elements like OnClick, OnDblClick, Top, Left, etc.
TObject >> TPersistent >> TComponent >> TControl |
IInterface |
Interfaces |
Base interface class. |
IUnknown |
Win 32 Specific Interfaces |
For Win32 specific interfaces. |
Step by Step Example
The following is a step-by-step tutorial on creating your first Delphi class and does include an inheritance example. From this simple tutorial, you can then experiment with the various class inheritance features.