1

Using: Delphi XE3, VCL Forms application

I have a menu containing a sub-menu in a ActionMainMenuBar. How can I via code:

  1. disable the menu
  2. disable the sub-menu
Steve F
  • 1,527
  • 1
  • 29
  • 55

3 Answers3

3
  1. Create a 'TAction' per menu/submenu that you want to enable disable. Do not assign them to any category.

  2. Create an 'OnExecute' event handler for these actions, so that these can be enabled. You don't have to put any code in the handler, a comment ('//') is enough for the IDE to not to delete the handlers.

  3. Select the 'TActionClient' that represents the menu/submenu from the form designer, just click on the item.

  4. Assign one of the actions to its 'Action' property in the object inspector.

  5. Enable/disable the action associated with the 'TActionClient' that represents the menu/submenu at run time for the menu/submenu to be enabled/disabled accordingly.

Sertac Akyuz
  • 54,131
  • 4
  • 102
  • 169
0

By using the 'enabled' property of the menu? or the menu-item that is the starting point of the submenu...

Copilot
  • 782
  • 6
  • 17
  • There isn't an enabled property... I am porting from DevExpress VCL dxBarManager (*in which the menu and submenu items do have an enabled property) to the standard VCL ActionManager and ActionMainMenuBar. – Steve F Jul 29 '13 at 07:48
  • That's odd, didn't you add 'Actions' to your ActionManager? These have enabled property. Also the ActionMainMenuBar itself has an enabled property (if you want to disable the full menu) – Copilot Jul 29 '13 at 08:38
  • A menu or a submenu on the ActionMainMenuBar is created by way of dragging the Action Category group to the ActionMainMenuBar. Since (the menu or submenu) its not a TAction, it does not consequently have an Enabled property. My question relates to whether anyone has found a workaround or hack to do this. – Steve F Jul 29 '13 at 11:09
0

You can actually disable it at runtime (in Delphi 7 anyway) if you know the index of the top-level menu item for the category as follows:

ActionMainMenuBar.ActionControls[2].Enabled := False;

ActionControls[2] would be the category showing as a top-level menu item (after dragging the category onto ActionMainMenuBar from ActionManager.

Jannie Gerber
  • 659
  • 1
  • 7
  • 15