Delphi TButton.OnClick 匿名函数用法


本文整理自网络,侵删。

 
type
  TNotifyEventRef = reference to procedure(Sender: TObject);

function AnonymousEvent(const Proc: TNotifyEventRef): TNotifyEvent;
type
  TVtable = array[0..3] of Pointer;
  PVtable = ^TVtable;
  PPVtable = ^PVtable;
begin
  TMethod(Result).Code := PPVtable((@Proc)^)^^[3];
  TMethod(Result).Data := Pointer((@Proc)^);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  //变态写法
  @Button1.OnClick := PPointer(Cardinal(PPointer(
    procedure(Sender: TObject)
    begin
      ShowMessage('你好,人民币!');
    end)^) + $0C)^;

  //正经写法
  Button2.OnClick := AnonymousEvent(
    procedure(Sender: TObject)
    begin
      ShowMessage('Hello,Money!');
    end);
end;

https://www.cnblogs.com/rtcmw/p/11022983.html

相关阅读 >>

Delphi中使用ado连接带密码的access

Delphi application.messagebox 详解

Delphi中如何判断mediaplayer控件所播放的文件是否播放完毕?

Delphi 实现产品编号批量生成简单算法

Delphi 去掉treeview水平滚动条

Delphi tapplication.onexception

Delphi memo 滚动条 自动滚到最后一行

Delphi什么是thttpclient?

Delphi doc转txt

Delphi 在 listbox 中放置一��可�� item 的 tedit �m件

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...