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 get all classes registered on a form 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
28-Oct-02
Category
VCL-Forms
Language
Delphi 2.x
Views
79
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

How can I get all classes that are currently registered in my application? Example: 
If I have a form with no components on it and I do something like ReadComponentRes 
and that *.dfm has a TEdit in it, I get an exception that TEdit is of unknown 
class. If I put one TEdit on that form and do ReadComponentRes again, everything 
goes OK. So, I guess TEdit is registered somewhere. Now I would like to find all 
registered classes so I would know which classes I can use in my *.dfm.

Answer:

There is no way to get at classes registered via RegisterClasses, since the list 
holding these is private to the classes unit. You can get at the classes registered 
on a form, however, since those use a table connected to the form classes class 
record. The following is based on some spelunking in the classes unit:

1   {defined in classes.pas}
2   type
3     PFieldClassTable = ^TFieldClassTable;
4     TFieldClassTable = packed record
5       Count: Smallint;
6       Classes: array[0..8191] of ^TPersistentClass;
7     end;
8   
9   function GetFieldClassTable(AClass: TClass): PFieldClassTable; assembler;
10  asm
11    MOV EAX, [EAX].vmtFieldTable
12    or EAX, EAX
13    JE @@1
14    MOV EAX, [EAX + 2].Integer
15    @@1:
16  end;
17  {end of quote from classes.pas}
18  
19  procedure TForm1.Button1Click(Sender: TObject);
20  
21    procedure Display(const S: string);
22    begin
23      memo1.lines.add(S);
24    end;
25  
26  var
27    pFCT: PFieldClassTable;
28    aClass: TClass;
29    i: SmallInt;
30  begin
31    memo1.clear;
32    aClass := Classtype;
33    while aClass < > TPersistent do
34    begin
35      Display('Registered classes for class ' + aClass.Classname);
36      pFCT := GetFieldClasstable(aClass);
37      if not Assigned(pFCT) then
38        Display('  No classes registered')
39      else
40      begin
41        Display(format('  %d classes registered', [pFCT^.Count]));
42        for i := 0 to pFCT^.Count - 1 do
43          Display('  ' + pFCT^.Classes[i]^.ClassName);
44      end;
45      aClass := aClass.ClassParent;
46    end;
47  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