Link to home
Start Free TrialLog in
Avatar of ginsonic
ginsonicFlag for Romania

asked on

Enable/disable my menu

I wish on some moment to disable all my menu items and after some time to enable.
How to do that?

Is easy to do a loop into menu and change the enable property, but I have (possible) some items already disabled.

How to know when re-enable the menu what menu's items was enabled and what was disabled before disable action? Sorry for this words game :)
Avatar of Knighty
Knighty

save the states of the menu in an array before disable it
Avatar of ginsonic

ASKER

Codes please
Avatar of kretzschmar
usual you must only disable the top-items,
for this just iterate through the main-menu-items

for i := 0 to mainmenu1.items.count-1 do
  mainmenu1.items[i].Enabled := YourSwitch;  //true or false

just from head, not tested

meikl ;-)
I know that (read my question), but the problem is that I have couple top items already disabled, too.
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
// Usage:

// Disable:
// EnableDisable(MainMenu1, False);

// Enable:
// EnableDisable(MainMenu1, True);

unit m;

interface

uses
  Menus;

procedure EnableDisable(const menu: TMainMenu; const enable: boolean);

implementation

procedure EnableDisable(const menu: TMainMenu; const enable: boolean);
var
  i: integer;
begin
  if enable then
  begin
    for i := 0 to (menu.Items.Count - 1) do
    begin
      menu.Items[i].Enabled := boolean(menu.Items[i].Tag);
    end;
  end
  else
  begin
    for i := 0 to (menu.Items.Count - 1) do
    begin
      menu.Items[i].Tag := Ord(menu.Items[i].Enabled);
      menu.Items[i].Enabled := enable;
    end;
  end;
end;

end.
Oops, little bug.

Never call enable before you disabled the menu. Otherwise all your menu items will be disabled.

Regards
Thanks for help :)