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;
作者:
oldfarmer
出处:
http://www.cnblogs.com/rtcmw/
欢迎探讨交流 DELPHI 相关技术,QQ:64445322 QQ群:734515869
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。