Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   Ayuda con sentencias for (https://www.clubdelphi.com/foros/showthread.php?t=77988)

escorpionrojo43 10-03-2012 18:53:05

Ayuda con sentencias for
 
Hola Amigo Estoy trabajando en las opciones de permiso pra mis programas el asunto es siguiente.
de la manera larga me funciona pero hace mas grande mi codigo.
Código Delphi [-]
//      Qry_Permisos.Active := true;
 //      if Qry_Permisos.FieldByName('OP1').AsBoolean = false then
 //        fmenuprincipal.Action1.Enabled := false;
//      if Qry_Permisos.FieldByName('OP2').AsBoolean = false then
 //        fmenuprincipal.Action2.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP3').AsBoolean = false then
 //        fmenuprincipal.Action3.Enabled := false;
 //      if Qry_Permisos.FieldByName('OP4').AsBoolean = false then
 //        fmenuprincipal.Action4.Enabled := false;
 //      if Qry_Permisos.FieldByName('OP5').AsBoolean = false then
 //        fmenuprincipal.Action5.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP6').AsBoolean = false then
 //        fmenuprincipal.Action6.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP7').AsBoolean = false then
 //        fmenuprincipal.Action7.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP8').AsBoolean = false then
 //        fmenuprincipal.Action8.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP9').AsBoolean = false then
 //        fmenuprincipal.Action9.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP10').AsBoolean = false then
 //        fmenuprincipal.Action10.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP11').AsBoolean = false then
 //        fmenuprincipal.Action11.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP12').AsBoolean = false then
 //        fmenuprincipal.Action12.Enabled := false;
 //      if Qry_Permisos.FieldByName('OP13').AsBoolean = false then
 //        fmenuprincipal.Action13.Enabled := false;
 //      if Qry_Permisos.FieldByName('OP14').AsBoolean = false then
 //        fmenuprincipal.Action14.Enabled := false;
 //      if Qry_Permisos.FieldByName('OP15').AsBoolean = false then
 //        fmenuprincipal.Action15.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP16').AsBoolean = false then
 //        fmenuprincipal.Action16.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP17').AsBoolean = false then
 //        fmenuprincipal.Action17.Enabled := false;
 //      if Qry_Permisos.FieldByName('OP18').AsBoolean = false then
 //        fmenuprincipal.Action18.Enabled := false;
//      if Qry_Permisos.FieldByName('OP19').AsBoolean = false then
 //        fmenuprincipal.Action19.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP20').AsBoolean = false then
 //        fmenuprincipal.Action20.Enabled := false;  
   end

El asunto es que necesito hacer esto un poco mejor y opte por utilizar las sentencia for

Código Delphi [-]
     with qry_permisos do 
        begin         
Active := true;
         first;         // x = 3 porque los primeros cuatro campo no son de las opciones mas bien son la llave
         for x:= 3 to FieldCount - 1 do         begin           //muestra el nombre del campo          
 campo := Fields.Fields[x].DisplayName;  
         for y := 0 to fmenuprincipal.ActionManager1.ActionCount - 1 do
            begin             //muestra el nombre del actions         
    with fmenuprincipal.ActionManager1.Actions[y] do   
            if index = x-3  then                
 if FieldByName(campo).AsBoolean = false then
                   enabled := false; 
           end;       
   end;      
   end;

la cosa es que con el for no me esta desabilitando los actions
por favor ayudenme con esto. gracias de antemano

duilioisola 10-03-2012 19:16:24

Código Delphi [-]
//      Qry_Permisos.Active := true; 
//      if Qry_Permisos.FieldByName('OP1').AsBoolean = false then 
//        fmenuprincipal.Action1.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP2').AsBoolean = false then 
//        fmenuprincipal.Action2.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP3').AsBoolean = false then 
//        fmenuprincipal.Action3.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP4').AsBoolean = false then 
//        fmenuprincipal.Action4.Enabled := false;
//      if Qry_Permisos.FieldByName('OP5').AsBoolean = false then 
//        fmenuprincipal.Action5.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP6').AsBoolean = false then 
//        fmenuprincipal.Action6.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP7').AsBoolean = false then 
//        fmenuprincipal.Action7.Enabled := false;
//      if Qry_Permisos.FieldByName('OP8').AsBoolean = false then 
//        fmenuprincipal.Action8.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP9').AsBoolean = false then 
//        fmenuprincipal.Action9.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP10').AsBoolean = false then 
//        fmenuprincipal.Action10.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP11').AsBoolean = false then 
//        fmenuprincipal.Action11.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP12').AsBoolean = false then 
//        fmenuprincipal.Action12.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP13').AsBoolean = false then 
//        fmenuprincipal.Action13.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP14').AsBoolean = false then 
//        fmenuprincipal.Action14.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP15').AsBoolean = false then 
//        fmenuprincipal.Action15.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP16').AsBoolean = false then 
//        fmenuprincipal.Action16.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP17').AsBoolean = false then 
//        fmenuprincipal.Action17.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP18').AsBoolean = false then 
//        fmenuprincipal.Action18.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP19').AsBoolean = false then 
//        fmenuprincipal.Action19.Enabled := false; 
//      if Qry_Permisos.FieldByName('OP20').AsBoolean = false then 
//        fmenuprincipal.Action20.Enabled := false;

Código Delphi [-]
with qry_permisos do         
begin         
   Active := true;         
   first;         
   // x = 3 porque los primeros cuatro campo no son de las opciones mas bien son la llave         
   for x := 3 to FieldCount - 1 do         
   begin           
      // muestra el nombre del campo           
      campo := Fields.Fields[x].DisplayName;           
      for y := 0 to fmenuprincipal.ActionManager1.ActionCount - 1 do            
      begin             
         // muestra el nombre del actions             
         with fmenuprincipal.ActionManager1.Actions[y] do               
            if index = x-3  then                 
               if FieldByName(campo).AsBoolean = false then                   
                  enabled := false;            
      end;           
   end;         
end;

El Index de la propiedad Actions[y] solo te da la posición dentro de la lista de acciones.
Supongo que deberías utilizar un método que te asegure que estás habilitando o deshabilitado la accion que quieres.
Por ejemplo, podrías utilizar su nombre o utilizar la propiedad Tag.

Yo en tu caso utilizaría algo así:

Código Delphi [-]
...
         // muestra el nombre del actions             
        for i := 0 to ComponentCount - 1 do
        begin
           if Components[i] is TAction then
           begin
              // Si el componente que busco se llama Action"nnn"
              // En realidad debería llamarse igual que en numero despues del nombre del campo OP"nnn" 
              if (TAction(Components[i]).Name = 'Action' + IntToStr(x)) then
                 TAction(Components[i]).Enabled := FieldByName(campo).AsBoolean;
           end;
        end;
...

escorpionrojo43 10-03-2012 19:32:46

Hermano gracias por tu respuesta.
El asunto con eso es que Cuando utilizo (TAction) desde el form principal no hay problemas pero cuando lo uso en form del login me dice
[DCC Error] ULogin.pas(91): E2003 Undeclared identifier: 'TAction'

no se supone que tome la declaracion del mismo form principal?

duilioisola 10-03-2012 21:38:38

Eso debe ser porque no tienes declarado en el Uses la unit que corresponde al TAction.
En el editor pon el cursor sobre la palabra TAction, presiona F1 y mira cual es la unit a la que pertenece.


La franja horaria es GMT +2. Ahora son las 13:34:51.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi