4

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!!!

menjaraz
  • 7,551
  • 4
  • 41
  • 81
maxfax
  • 4,281
  • 12
  • 74
  • 120
  • 1
    Suppose you have a button, `button1`, with its `Action` property set to `myAction`. If you want the button to be invisible then you simply set `myAction.Visible := False`. This results in the action not being invokeable. Now, your question makes hardly any sense at all in its current state and I expect this comment isn't what you are looking for. I recommend that you try to explain your problem more clearly. – David Heffernan Jul 19 '11 at 17:48
  • 2
    `MyAction.Enabled := False` ? – Sertac Akyuz Jul 19 '11 at 18:01
  • 1
    @David - With a simple test, setting visibility of an action to false does not seem to prevent the action executing with a shortcut. – Sertac Akyuz Jul 19 '11 at 18:04
  • I have made the question more clear. – maxfax Jul 19 '11 at 18:09
  • 1
    @David: to make an action uninvokable you need to disable it, or nil its onexecute handler (provided DisableIfNoHandler is true, the default). Visibility is not checked in TCustomAction's Execute method (nor in its ancestors). – Marjan Venema Jul 19 '11 at 18:38
  • @David: Not surprising at all. Doing this with menu items was a way in early versions of Delphi to assign hotkeys - you create the menu item, write it's OnClick, set a shortcut key, and make the menu item invisible. – Ken White Jul 19 '11 at 20:45
  • I guess one is never to old to learn new things. Thanks all! – David Heffernan Jul 19 '11 at 20:50

2 Answers2

6

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.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
1

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

Johan
  • 74,508
  • 24
  • 191
  • 319
  • @David it will, but some other shortcut is probably^H^H^H might intercept the keystroke. So I was setting out a way too enable the OP to understand where the stange behavior is coming from (i.e. not from the actionlist). – Johan Jul 19 '11 at 18:28