TGraphicClass defines the metaclass for TGraphic.
TGraphicClass = class of TGraphic;
TGraphic TGraphicClass;
Graphics
TGraphicClass is the metaclass for TGraphic. Its value is the class reference for TGraphic or for one of its descendants.
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. */ TMetaClass *MetaClass; void __fastcall TForm1::Button1Click(TObject *Sender) { 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); }
Delphi 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. } uses ExtCtrls; procedure TForm1.Button1Click(Sender: TObject); var myClassFinder: TClassFinder; mygraphclass: TGraphicClass; begin { make sure the classes are registered so that GetClass will work -- } { Usually, this goes in the initialization section where it is only executed once } RegisterClasses([TIcon, TBitmap, TButton, TShape, TImage, TMetafile]); try myClassFinder := TClassFinder.Create(TIcon, False); mygraphclass := TGraphicClass(myClassFinder.GetClass(Edit2.Text)); // mygraphclass := TGraphicClass(GetClass(Edit2.Text)); // works as well Edit1.Text := GraphicExtension(mygraphclass); except on EAccessViolation do MessageDlg('Invalid class name.', mtError, [mbOK], 0) end; end;
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|