Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

runtime

delphi

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 user what forms are opened without needing to open a "Windows" menu in the main menu.

I have an unit named NavigationUtils.pas that I use to store the procedures / functions about navigation (as the creation of the buttons when my forms are created).

The question is: How can I configure the OnClick event when the ToolButtons are created?

like image 955
juniorgarcia Avatar asked Dec 20 '12 11:12

juniorgarcia


1 Answers

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;
like image 101
David Heffernan Avatar answered Nov 04 '22 09:11

David Heffernan