ay caro tienes razon, lo escribi rapido y sin mirarlo mucho
:
Código Delphi
[-]
const
menus_a_desactivar : string = 'general, menu1,menu2,...etc';
function MirarSiEsMenuADesactivar(c : TMenuItem) : boolean;
begin
result := Pos(Lowercase(Trim(stringreplace(c.Caption,'&','',[rfIgnoreCase,rfReplaceAll]))),menus_a_desactivar) <> 0;
end;
procedure Desactivar(c : TComponent);
var
i : integer
begin
for i := 0 to c.ComponentCount - 1 do
Desactivar(c.Components[i]);
if c is TMenuItem then
if MirarSiEsMenuADesactivar(c) then
try
(c as TMenuItem).Enabled := false;
except end;
end;
...
if nivel_usuario < 2 then Desactivar(Application);
...
seria algo asi. Otra manera tambien seria teniendo los nombres de los TMenuItems en una lista (los nombres tal cual: MenuItem1, MenuItem2,...en el otro ejemplo se buscaban por 'caption') y hacer algo como
Código Delphi
[-]
var
s : TStringList;
begin
s := TStringList.Create(self);
s.Add('MenuItem1');
s.Add('General1');
s.Add('VerForm1')
for i := 0 to s.Count - 1 do
(Application.FindComponent(s[i]) as TMenuItem).Enabled := nivel_usuario < 2;
s.Free;
Mas o menos son equivalentes. saludos.