Articles   Members Online:
-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 a list of all published methods for a given class 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 2.x
Views
136
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

Is there a way to get a list of all published methods for a given class? 
Preferably, I'd like to fill a TList with references to them, but even the text 
representation would work.

Answer:

Enumerate the published methods of a class and all its ancestor classes:

1   procedure EnumMethods(aClass: TClass; lines: TStrings);
2   
3   type
4     TMethodtableEntry = packed record
5       len: Word;
6       adr: Pointer;
7       name: ShortString;
8     end;
9     {Note: name occupies only the size required, so it is not a true shortstring!
10  	The actual entry size is variable, so the method table is not an array
11  	of 	TMethodTableEntry!}
12  
13  var
14    pp: ^Pointer;
15    pMethodTable: Pointer;
16    pMethodEntry: ^TMethodTableEntry;
17    i, numEntries: Word;
18  begin
19    if aClass = nil then
20      Exit;
21    pp := Pointer(Integer(aClass) + vmtMethodtable);
22    pMethodTable := pp^;
23    lines.Add(format('Class %s: method table at %p', [aClass.Classname, 
24  pMethodTable]));
25    if pMethodtable <> nil then
26    begin
27      {first word of the method table contains the number of entries}
28      numEntries := PWord(pMethodTable)^;
29      lines.Add(format('  %d published methods', [numEntries]));
30      {make pointer to first method entry, it starts at the second word of the table}
31      pMethodEntry := Pointer(Integer(pMethodTable) + 2);
32      for i := 1 to numEntries do
33      begin
34        with pMethodEntry^ do
35          lines.Add(format('  %d: len: %d, adr: %p, name: %s', [i, len, adr, name]));
36        {make pointer to next method entry}
37        pMethodEntry := Pointer(Integer(pMethodEntry) + pMethodEntry^.len);
38      end;
39    end;
40    EnumMethods(aClass.ClassParent, lines);
41  end;
42  
43  procedure TForm2.Button1Click(Sender: TObject);
44  begin
45    memo1.clear;
46    EnumMethods(Classtype, memo1.lines);
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