Author: Jonas Bilinkevicius
If I am given a TPersistent object, and a method name, is there a way to determine
if the name is an event of TNotifyEvent type? For example, given a TPersistent
lMyObj and an event name, "OnDataChanged", how can I determine if OnDataChanged is
a TNotifyEvent?
Answer:
1 function IsNotifyEvent(Sender: TObject; const Event: string): Boolean;
2 var3 PropInfo: PPropInfo;
4 Method: TNotifyEvent;
5 begin6 Result := False;
7 PropInfo := GetPropInfo(Sender.ClassInfo, Event);
8 ifnot Assigned(PropInfo) then9 Exit;
10 if PropInfo.PropType^.Kind <> tkMethod then11 Exit;
12 Method := TNotifyEvent(GetMethodProp(Sender, PropInfo));
13 Result := Assigned(Method);
14 end;