1. Home
  2. Computing & Technology
  3. Delphi Programming

Get the list of events with attached event handlers

By Zarko Gajic, About.com

In Delphi for Win32 OOP, an event of an object might be handled by one method (event handler). Here's how to get the list of those events of an object, that have a handler attached...

Use the next code for the OnCreate handler of a Form1 object (TForm). Place two ListBox'es on the form, and run ...

ListBox1 holds the names of all events of the Form1 object, ListBox2 only those having a handler attached.

~~~~~~~~~~~~~~~~~~~~~~~~~
USES TYPINFO, .... !!!!


procedure TForm1.FormCreate(Sender: TObject) ;
var
Count, Loop: Integer;
List: PPropList;
method : TMethod;
begin
Count := GetPropList(TypeInfo(TForm1), tkMethods, nil) ;
GetMem(List, Count * SizeOf(PPropInfo)) ;
try
GetPropList(TypeInfo(TForm1), tkMethods, List) ;
for Loop := 0 to Pred(Count) do
begin
Listbox1.Items.Add(List[Loop]^.Name) ;
method := GetMethodProp(Form1, List[Loop]^.Name) ;
if Assigned(method.Code) and Assigned(method.Data) then
begin
ListBox2.Items.Add(List[Loop]^.Name) ;
end;
end;
finally
FreeMem(List, Count * SizeOf(PPropInfo))
end;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Note: once you know the name of the event with the handler attached, here's how to execute a method by its name

Delphi tips navigator:
» How to create a Console mode application Without a console window
« Setting a multi-line Caption for a TLabel (at design-time)

More Delphi Programming Quick Tips
Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2005 Delphi Tips
  7. Get the list of events with attached event handlers (Delphi for Win32)

©2009 About.com, a part of The New York Times Company.

All rights reserved.