Is there a way in Delphi to assign an anonymous method to a button event?

后端 未结 1 1057
执笔经年
执笔经年 2021-01-17 23:52

I was wondering if there is a way in Delphi to assign an anonymous method to a form control event.

For example:

Button1.OnClick := procedure (Sender:         


        
相关标签:
1条回答
  • 2021-01-18 00:34

    This is not possible. You have to make the event handler be a method type rather than an anonymous method.

    You'll need to wrap your anonymous method in a method. Either an instance method (of a record or a class), or a class method. For instance:

    • VCL events with anonymous methods - what do you think about this implementation?
    • TProc<TObject> to TNotifyEvent
    0 讨论(0)
提交回复
热议问题