Articles   Members Online: 3
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to dynamically retrieve class information Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
19-Oct-02
Category
Object Pascal
Language
Delphi All Versions
Views
149
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

How to dynamically retrieve class information

Answer:

This will create an instance of the class specified in the GetClass call:

1   procedure TForm1.FormCreate(Sender: TObject);
2   begin
3     {This only works for classes registered using RegisterClass}
4     RegisterClasses([TButton, TForm]);
5   end;
6   
7   procedure TForm1.Button1Click(Sender: TObject);
8   var
9     CRef: TPersistentClass;
10    PTI: PTypeInfo;
11    AControl: TControl;
12  begin
13    CRef := GetClass('TButton');
14    if CRef <> nil then
15    begin
16      AControl := TControl(TControlClass(CRef).Create(Self));
17      with AControl do
18      begin
19        Parent := Self;
20        Width := 50;
21        Height := 30;
22      end;
23      Inc(Id);
24    end
25    else
26      MessageDlg('No such class', mtWarning, [mbOk], 0);
27  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC