频道分类

Delphi TButton.OnClick 匿名函数用法

作者:admin 来源: 日期:2020/3/23 21:23:46 人气: 标签:

 
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 idhttp post json 上传 PHP 接收下一篇:没有资料