Ir al contenido


Foto

[RESUELTO] Deshabilitar Accion del TActionManager


  • Por favor identifícate para responder
6 respuestas en este tema

#1 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 16 diciembre 2009 - 06:21

Hola

Estoy iniciando un desarrollo y entre otras cosas necesito deshabilitar una acción del TActionManager desde su propiedad Enabled.

¿Alguien sabe como puedo hacer eso en tiempo de ejecución?

Salud OS

Les muestro una imagen de lo que necesito para ser más claro.

  • 0

#2 escafandra

escafandra

    Advanced Member

  • Administrador
  • 4.107 mensajes
  • LocationMadrid - España

Escrito 16 diciembre 2009 - 06:41

Pues basta con poner:


delphi
  1. usuarios.enabled:= false;



Saludos.
  • 0

#3 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 16 diciembre 2009 - 06:47

Gracias amigo, pero creo que omití algo importante, estoy haciendo esto en una función dependiendo del tag que tiene cada accion, ya había pensado en esa posibilidad pero no logro obtener el nombre de la accion, este es parte del código:



delphi
  1. var
  2.   i: integer;
  3.   Acciones: TActionClientItem;
  4. begin
  5.   for i := 0 to ActionManager1.ActionCount - 1 do begin
  6.       if ActionManager1.Actions[i].Tag = Privilegios[i] then
  7.         ShowMessage(inttostr(ActionManager1.Actions[i].tag));
  8.   end;
  9. end;



Salud OS
  • 0

#4 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 16 diciembre 2009 - 09:31

Hola

Pues encontré una forma diferente de hacer las cosas, no estoy deshabilitando las acciones, lo que hago es hacerlas invisibles. De cualquier forma seguiré investigando hasta encontrar lo que había imaginado inicialmente :)



delphi
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   i: integer;
  4. begin
  5.   Privilegios[1] := 0; //Para prueba inicialice a cero este item.
  6.   for i := 0 to ActionManager1.ActionCount-1 do begin
  7.       if ActionManager1.ActionBars[0].Items[i].Tag = Privilegios[i] then begin
  8.         ActionManager1.ActionBars[0].Items[i].Visible := true;
  9.       end
  10.       else begin
  11.             ActionManager1.ActionBars[0].Items[i].Visible := false;
  12.       end;
  13.   end;
  14. end;
  15.  
  16. procedure TForm1.FormShow(Sender: TObject);
  17. var
  18.   i: integer;
  19. begin
  20.   for i := 0 to ActionManager1.ActionCount-1 do begin
  21.       if ActionManager1.ActionBars[0].Items[i].Tag = Privilegios[i] then begin
  22.         ActionManager1.ActionBars[0].Items[i].Visible := true;
  23.       end
  24.       else begin
  25.             ActionManager1.ActionBars[0].Items[i].Visible := false;
  26.       end;
  27.   end;
  28. end;



Salud OS
  • 0

#5 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 16 diciembre 2009 - 11:12

Hola

Tuve un problema de indices al colocar las acciones por categorías y finalmente el código quedó de la siguiente forma.



delphi
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   i: integer;
  4. begin
  5.   Privilegios := [];
  6.   Include(Privilegios,101);
  7.   Include(Privilegios,102);
  8.   for i := 0 to ActionManager1.ActionCount-1 do begin
  9.       if ActionManager1.Actions[i].Tag in Privilegios then begin
  10.         (ActionManager1.Actions[i] as TAction).enabled := true;
  11.       end
  12.       else begin
  13.         (ActionManager1.Actions[i] as TAction).enabled := false;
  14.     end;
  15.   end;
  16. end;
  17.  
  18. procedure TForm1.FormShow(Sender: TObject);
  19. var
  20.   i: integer;
  21. begin
  22.   Privilegios := [];
  23.   Include(Privilegios,100);
  24.   Include(Privilegios,101);
  25.   Include(Privilegios,102);
  26.   for i := 0 to ActionManager1.ActionCount-1 do begin
  27.       if ActionManager1.Actions[i].Tag in Privilegios then begin
  28.         (ActionManager1.Actions[i] as TAction).enabled := true;
  29.       end
  30.       else begin
  31.         (ActionManager1.Actions[i] as TAction).enabled := false;
  32.     end;
  33.   end;
  34. end;



Salud OS
  • 0

#6 paoti

paoti

    Member

  • Miembros
  • PipPip
  • 12 mensajes
  • LocationMonterrey

Escrito 04 febrero 2010 - 04:25

Hola egostar.


pporque no usas el evento Update del Taction.

citando a la ayuda:

Occurs when the application is idle or when the action list updates.
Write an OnUpdate event handler to execute centralized code while an application is idle. For example, actions may want to update enabling and disabling, or checking and unchecking of client targets.



y ahi pondrias:




delphi
  1. (Sender as TAction).enabled  := HacerAlgoConElTag(
  2. (Sender as TAction).tag);



así, este evento controla el comportamiento de su acción, en el tiempo idle de la app.


espero te sirva.




  • 0

#7 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 04 febrero 2010 - 04:45

Ah vaya, intentaré usar este concepto y te comento que sucedió :)

Salud OS
  • 0




IP.Board spam blocked by CleanTalk.