Mega Code Archive

 
Categories / Delphi / Ide Indy
 

Get the list of events with attached event handlers (Delphi for Win32)

Title: Get the list of events with attached event handlers (Delphi for Win32) 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