Question

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
Was it helpful?

Solution

  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.

OTHER TIPS

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top