How to check if two events are pointing to the same procedure in Delphi?

后端 未结 3 1847
故里飘歌
故里飘歌 2020-12-01 16:27

Say I have a Button1.OnClick event linked to Button1Click procedure. I also have Button2.OnClick linked to some other procedure. How do I check that both events are linked t

3条回答
  •  北海茫月
    2020-12-01 17:03

    I do it with this function:

    function MethodPointersEqual(const MethodPointer1, MethodPointer2): Boolean;
    var
      Method1: System.TMethod absolute MethodPointer1;
      Method2: System.TMethod absolute MethodPointer2;
    begin
      Result := (Method1.Code=Method2.Code) and (Method1.Data=Method2.Data)
    end;
    

    It works, but if someone knows a less hacky way to do it then I'd love to hear about it!

提交回复
热议问题