Delphi: disable 1 Action from Action List

4.6k Views Asked by At

It is funny :) but how to do something like ActionList1.MyAction.Enable:=false?

An Action List has actions for buttons, if a button is invisible I need to disable it's action (if not to do this and pres a shortcut then a procedure will be performed).

May be I do something wrong, but I did not assign actions to buttons. I have only an Action List with Actions. Each action has a shortcut. When this shortcut is pressed then the action is executed and it performs a procedure. If to click on the button -> the same procedure will be performed too.

State:=asSuspended is for a whole Action List.

Thanks!!!

2

There are 2 best solutions below

0
On BEST ANSWER

You should assign the button's Action property and control everything via the action. Set the action to be disabled, invisible etc. and the button follows suit.

Don't set the OnClick event handler of the button, instead use the corresponding event of the action. Use the action's OnUpdate event to set properties like Visible, Enabled etc., basically everything that changes at runtime.

1
On

TActionList is a list containing one or more TAction's.

TAction has the following properties:
AutoCheck
Caption
Checked
Enabled
GroupIndex
HelpContext
HelpKeyword
HelpType
Hint
ImageIndex
SecondaryShortCuts
ShortCut
Visible

Enabled should work just fine as long as your follow David's advice and do everything using the TActionList.

Alternatively if taction.enabled doesn't work for you, you can always test to see if setting actionxxxx.shortcut := ''; does the trick.
If not then some other shortcut is intercepting the keystroke.

See:
http://docwiki.embarcadero.com/VCL/XE/en/ActnList.TAction
http://docwiki.embarcadero.com/VCL/en/ActnList.TActionList