Delphi的函数指针

时间:2014-05-12 20:58:45   收藏:0   阅读:432

不求全面,先留个爪:

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

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

bubuko.com,布布扣
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;
bubuko.com,布布扣

 参考:

http://blog.csdn.net/linzhengqun/article/details/1755493

Delphi的函数指针,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!