Ver Mensaje Individual
  #7  
Antiguo 14-11-2012
cloayza cloayza is offline
Miembro
 
Registrado: may 2003
Ubicación: San Pedro de la Paz, Chile
Posts: 913
Reputación: 22
cloayza Tiene un aura espectacularcloayza Tiene un aura espectacular
Para estos menesteres me inclino por el uso de la RTTI

Código Delphi [-]
uses TypInfo;
...

function ExistProperty(AComp: TComponent; APropName: String):Boolean;  
var                                                                    
  PropInfo: PPropInfo;                                                 
begin                                                                  
     PropInfo := GetPropInfo(AComp.ClassInfo, APropName);              
     Result:=Assigned(PropInfo);                                       
end;                                                                   

procedure SetBooleanProperty(AComp: TComponent; APropName: String; AValue: Boolean);  
var                                                                                   
  PropInfo: PPropInfo;                                                                
begin                                                                                 
     PropInfo := GetPropInfo(AComp.ClassInfo, APropName);                             
     if PropInfo <> nil then                                                          
     begin                                                                            
          if PropInfo^.PropType^.Kind = tkEnumeration then                            
            SetOrdProp(AComp, PropInfo, Integer(AValue));                             
     end;                                                                             
end;                                                                                  

procedure TForm1.Button2Click(Sender: TObject);
var
   Control : Array[1..6] of TComponent;
   i : Integer;

begin

   // El arreglo contiene los nombres de los componentes a gestionar (Propiedad Name)
   Control[1] := Label1;
   Control[2] := Label2;
   Control[3] := Label3;
   Control[4] := Edit1;
   Control[5] := Edit2;
   Control[6] := Edit3;

   for i := 1 to 6 do
       if ExistProperty(Control[1],'Enabled') then
          SetBooleanProperty(Control[1],'Enabled', True);  
end;
Saludos cordiales
Responder Con Cita