ginsonic
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 :)
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 :)
save the states of the menu in an array before disable it
ASKER
Codes please
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 ;-)
for this just iterate through the main-menu-items
for i := 0 to mainmenu1.items.count-1 do
mainmenu1.items[i].Enabled
just from head, not tested
meikl ;-)
ASKER
I know that (read my question), but the problem is that I have couple top items already disabled, too.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
// 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.
// 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
Never call enable before you disabled the menu. Otherwise all your menu items will be disabled.
Regards
ASKER
Thanks for help :)