Ver Mensaje Individual
  #8  
Antiguo 21-07-2004
Avatar de ruina
ruina ruina is offline
Miembro
 
Registrado: jun 2004
Posts: 196
Reputación: 20
ruina Va por buen camino
bueno, tenia un ratillo libre asi que le he dado un por de vueltas de tuerca al asunto.


Bien, estabamos en que podiamos asignar propieades a las Clases o a instancias concretas por el Nombre del componente, pero...
No podiamos hacer algo tan util como:
Código:
[TLabel]
 Font.Name=MS Sans Serif
!!
afortunadamente podemos usar la función GetObjectProp, basicamente es GetOrdProp con un resultado formateado a Tobjetc

Bueno, me dejo de rollos y meto codigo (he intentado que sea lo menos criptico posible):
Código Delphi [-]
procedure TForm1.BitBtn1Click(Sender: TObject);
  procedure RellenarPropiedades(NombreSeccion:string;Componente:Tcomponent);
  var k:integer;
      valor:string;
      SL:TStringList;
      pinfopropinfo; // está en TypInfo
      NombrePropiedad,NombreSubPropiedad:string; //Ej:'Font.Size'
      SubObjeto:TObject;
  begin
      SL:=TStringList.Create;
      try
          ini.ReadSection(NombreSeccion,SL);
          for k:=0 to SL.count-1 do  //recorremos la seccion entera:
          begin
               if pos('.',SL[k])>0 then
               begin
                    NombrePropiedad:=copy(SL[k],1,pos('.',SL[k])-1);
                    NombreSubPropiedad:=copy(SL[k],pos('.',SL[k])+1,length(SL[k]));
               end
               else
               begin
                    NombrePropiedad:=SL[k];
                    NombreSubPropiedad:='';
               end;
               pinfo:=GetPropInfo(Componente.ClassInfo,NombrePropiedad); //pillamos la información de la propiedad
               if pinfo<>nil then
               begin
                    Valor:=ini.ReadString(NombreSeccion,SL[K],'');
                    if Valor<>'' then
                    begin
                          if NombreSubPropiedad='' then
                             SetPropValue(Componente,NombrePropiedad,valor) //asignamos el valor
                          else
                          begin
                                SubObjeto:=GetObjectProp(Componente,pinfo.Name); // en este caso (Font.name) primero sacamos la instancia a la propiedad
                                if GetPropinfo(SubObjeto,NombreSubPropiedad)<>nil then
                                   SetPropValue(SubObjeto,NombreSubPropiedad,valor); //y asignamos el valor!!
                          end;
                    end;
               end;
          end;
        finally
            SL.Free;
        end;
  end;
var i:integer;
begin
      for i:=0 To ComponentCount-1 DO
      begin
            RellenarPropiedades(Components[i].ClassName,Components[i]);
            RellenarPropiedades(Components[i].Name,Components[i]);
      end;
      RellenarPropiedades(name,self);
end;
Responder Con Cita