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 store form method pointers in a TList 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
30-Aug-02
Category
VCL-General
Language
Delphi 2.x
Views
107
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

What is the correct way to store form method pointers on a TList then use the TList 
items[] to call the various procedures?

Answer:

This isn't as easy as it seems. Despite the name, method pointers aren't pointers, 
they're 8-byte records (type TMethod, check the Help). So, you have to New a 
TMethod on the heap for each method pointer you want to store to the list, and of 
course free the records before you clear or free the list:


1   type
2     TmyMethod = procedure(s: string) of object;
3     TpMyMethod = ^TmyMethod;
4     TpMethPtr = ^Tmethod;
5   
6   procedure addMethodPointer(lst: TList; mp: TmyMethod);
7   var
8     p: TpMethPtr;
9   begin
10    new(p);
11    p^ := Tmethod(mp);
12    lst.add(p);
13  end;
14  
15  procedure clearPointers(lst: TList);
16  var
17    j: integer;
18  begin
19    for j := 0 to lst.count - 1 do
20    begin
21      dispose(TpMethPtr(lst[j]));
22    end;
23  end;



The fancy casting in addMethodPointer is so you can change the parameter type for 
mp without changing anything else.

The call to a given pointer goes this way:

24  
25  TpMyMethod(lst[1])^(myString);


			
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