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-dbgrid取得所有表中的值

Delphi idhttp.get方法

Delphi开发ie右键菜单扩展

Delphi 内进行音量控制及静音

Delphi时间格式错误

Delphi 泛型数组 strsplit 字符串分割

Delphi stringgrid 加载excel表格文件内容自动宽度

Delphi10及以上版本安装activex控件

Delphi tparallel并行性能测试

Delphi xe下文件转base64编码函数

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



打赏

取消

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

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

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

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

评论

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