delphi指针函数

来源:互联网 发布:Mac大括号怎么打 编辑:程序博客网 时间:2024/06/01 21:49

不求全面,先留个爪:

  TNotifyEvent = procedure(Sender: TObject) of object;  TMethod = record    Code, Data: Pointer;  end;

判断两个按钮的事件是否相等:

复制代码
procedure TForm1.Button5Click(Sender: TObject);var  f1,f2: TNotifyEvent;begin  f1:=Button1.OnClick;  f2:=Button2.OnClick;  if (@f1=@f2) then begin ShowMessage('相等'); end  else begin ShowMessage('不相等'); end;end;procedure TForm1.Button6Click(Sender: TObject);var  t1,t2: TMethod;begin  t1:=TMethod(Button1.OnClick);  t2:=TMethod(Button2.OnClick);  if t1.Code=t2.Code then    showmessage('method.Code is same');  if t1.Data=t2.Data then    showmessage('method.Data is same');end;procedure TForm1.Button7Click(Sender: TObject);begin  if Addr(Button1.OnClick)=Addr(Button2.OnClick) then    showmessage('ffffff');end;
复制代码