RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TMetaClass Class

System::TMetaClass is the C++ representation of the Delphi class-reference type.

Pascal
TMetaClass = class;
C++
class TMetaClass;

System::TMetaClass allows operations to be performed directly on classes. This contrasts with class types, which can be instantiated as objects and which allow operations to be performed on those instances. The System::TMetaClass for a given class can be acquired by using the __classid keyword extension. 

A variable of type System::TMetaClass can be NULL, which indicates that the variable does not currently reference a class. 

Every class inherits a method function called ClassType, which returns a reference to the class of an object. The type of the value returned by ClassType is TClass (System::TMetaClass*), which is a pointer to a System::TMetaClass. 

The methods of System::TMetaClass correspond to the static methods of TObject. They have the same functionality but differ in parameters. Whereas the TObject methods take a TClass (System::TMetaClass*) as the first parameter, this parameter is implicit in the System::TMetaClass methods.  

C++ Examples: 

 

/*
The following example allows users to type the name of a
graphics class into an edit control and when a button is
pressed, the name of the default extension for that class is
displayed in another edit control.  In the form’s OnCreate
event handler (or a similar place) you must register the
graphics classes so that GetClass can find them.
*/
#include <memory>       //for STL auto_ptr class

TMetaClass *MetaClass;

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  std::auto_ptr<TClassFinder> myClassFinder(new TClassFinder(MetaClass, False));
  TGraphicClass mygraphclass = (TGraphicClass) (myClassFinder->GetClass(Edit2->Text));
//  TGraphicClass mygraphclass = (TGraphicClass) GetClass(Edit2->Text);
  Edit1->Text = GraphicExtension(mygraphclass);
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  MetaClass = __classid(TIcon); // ico
  RegisterClasses(&MetaClass, 0);
  MetaClass = __classid(Graphics::TBitmap); // bmp
  RegisterClasses(&MetaClass, 0);
  MetaClass = __classid(TMetafile); // emf
  RegisterClasses(&MetaClass, 0);
  MetaClass = __classid(TShape);  // nographic extension
  RegisterClasses(&MetaClass, 0);
  MetaClass = __classid(TImage); // nographic extension
  RegisterClasses(&MetaClass, 0);
}

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!