Recent

Author Topic: Problem in Toolbuttons with Actions  (Read 986 times)

simsee

  • Full Member
  • ***
  • Posts: 226
Problem in Toolbuttons with Actions
« on: August 04, 2025, 12:09:44 am »
I'm definitely missing something obvious... In the attached program, I have a toolbar with three toolbuttons, each associated with a different action. For reasons I don't understand, when the program runs, all three toolbuttons are disabled. Why? Thanks, and sorry for the trivial nature of the question.

jamie

  • Hero Member
  • *****
  • Posts: 7302
Re: Problem in Toolbuttons with Actions
« Reply #1 on: August 04, 2025, 12:30:03 am »
I didn't look at your code, but I just tried something similar, and I found you need to assign the OnExecute event of each Action and then the button will be enabled.

 Honestly, I never understood the value of Actions!

Jamie

The only true wisdom is knowing you know nothing

simsee

  • Full Member
  • ***
  • Posts: 226
Re: Problem in Toolbuttons with Actions
« Reply #2 on: August 04, 2025, 12:33:25 am »
So if OnExecute isn't assigned in the Action, the control associated with it is disabled? I didn't know that...

jamie

  • Hero Member
  • *****
  • Posts: 7302
Re: Problem in Toolbuttons with Actions
« Reply #3 on: August 04, 2025, 12:36:07 am »
You can always assign them to a dummy event.
The only true wisdom is knowing you know nothing

simsee

  • Full Member
  • ***
  • Posts: 226
Re: Problem in Toolbuttons with Actions
« Reply #4 on: August 04, 2025, 06:48:01 pm »
Thanks, Jamie. One more question, if I may. Perhaps I'm misunderstanding the meaning of TAction.Checked. In the case of a tbscheck toolbutton, if it's down, why the Checked property of the associated action is false (see screenshot)? Thanks.

wp

  • Hero Member
  • *****
  • Posts: 13199
Re: Problem in Toolbuttons with Actions
« Reply #5 on: August 04, 2025, 07:35:26 pm »
You must turn on the Action's AutoCheck property so that it checks/unchecks itself when the associated control changes its checked state. Or, when you prefer to keep AutoCheck = false, you must toggle the state yourself:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Action1Execute(Sender: TObject);
  2. begin
  3.   Action1.Checked := not Action1.Checked;
  4. end;

In both cases, the button's style can stay at tbsButton (tbsCheck not required) because the button is fully controlled by the action then.

The advantage is that any action-aware control associated with this action (a menu item, a checkbox) will be checked in the same way (unfortunately there is no good visual feedback for checked/uncheck menu item state any more these days).

There is a nice article about Actions by Brian Long: http://blong.com/Articles/Actions/Actions.htm (just skip the chapter about ActionManager which does not exist in Lazarus).
« Last Edit: August 04, 2025, 07:58:19 pm by wp »

 

TinyPortal © 2005-2018