How can I assign the OnClick event of a ToolButton at runtime?

前端 未结 1 480
一个人的身影
一个人的身影 2021-01-05 10:03

I have a TToolBar created in design time with no ToolButtons. My idea is to create ToolButtons in runtime and place them there when my forms are created, just to show the us

相关标签:
1条回答
  • 2021-01-05 10:23

    From the comments it is clear that you are not assigning a TNotifyEvent to the OnClick event. The declaration of TNotifyEvent is:

    TNotifyEvent = procedure(Sender: TObject) of object;
    

    So you need a procedure, with a single parameter of type TObject, and the procedure must be the method of an object. So, something like this:

    procedure TMyForm.ToolButtonClick(Sender: TObject);
    

    And then you can assign it like so:

    NewToolButton.OnClick := ToolButtonClick;
    
    0 讨论(0)
提交回复
热议问题