0

I add toolbar buttons dynamically based on settings file. I would like to assign TAction to them. For now I added OnClick event with action OnExecute handler but if action is disabled, then toolbar button is not disabled automatically like for example TMenuItems added at design time.

So, in other words, I'd like to have runtime version of design time assigning TAction using "Action" dropdown menu in IDE.

Here is what I did so far (the code is C++ but it's obvious what it does).

TToolButton *b;
b = new TToolButton(ToolBar1);
b->Action = Form1->ActionManager1->Actions[0];
b->Parent = ToolBar1;

This adds button to ToolBar and it seems to follow action enabled/disabled state but when clicked nothing happens. How do I add action properly and fully?

Coder12345
  • 3,431
  • 3
  • 33
  • 73

1 Answers1

4

TToolButton has a published Action property. Simply assign your desired TAction object to that property.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • I did try that (see code above) but it doesn't react to OnClick event, either I assigned it incorrectly when adding button or something else needs to be done. A small piece of example code would be of great help. – Coder12345 Apr 23 '12 at 16:37
  • Works fine for me using the exact code you showed. The `TAction.OnExecute` event is triggered when the `TToolButton` is clicked – Remy Lebeau Apr 23 '12 at 23:13
  • I've tried with small test program and it works for me too. It must be I messed up something else with larger program where it doesn't work and probably assigned OnClick somewhere where I didn't look. Thanks for help. – Coder12345 Apr 24 '12 at 01:59