Can I use a closure on an event handler (ie, TButton OnClick)

前端 未结 4 2000
迷失自我
迷失自我 2020-12-24 03:44

If I try to use a closure on an event handler the compiler complains with :

Incompatible types: \"method pointer and regular procedure\"

which I understand..

4条回答
  •  青春惊慌失措
    2020-12-24 04:14

    @Button1.OnClick := pPointer(Cardinal(pPointer( procedure (sender: tObject) 
    begin 
      ((sender as TButton).Owner as TForm).Caption := 'Freedom to anonymous methods!' 
    
    end )^ ) + $0C)^;
    

    works in Delphi 2010

提交回复
热议问题