The Visual Component Library (VCL) has a general class called TObject. This class is used as the ancestor of all other classes. Most of the time, you should never declare an instance of the  TObject class but you can refer to it in casting needs. To lay the foundation of the VCL classes, TObject provides a series of methods that other classes can use. 

TObject Methods




The  ClassNameIs() method allows you to check the type of class that an object is made of. Therefore, it can be used to identify a class. For example, you can write code for a common event shared by various controls. Imagine you have a series of panels whose colors you want to assign to another control when one of these panels is clicked:

Instead of writing an OnClick event for each panel, you can select all panel controls (using Shift + Click) then double-click the OnClick event in the Object Inspector and implement the event as follofws:
void __fastcall TForm1::Panel3Click(TObject *Sender)
    if( Sender->ClassNameIs("TPanel") )
        Panel1->Color = dynamic_cast<TPanel *>(Sender)->Color;




Copyright © 2003-2007 FunctionX, Inc.