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; SubObjeto:TObject;
begin
SL:=TStringList.Create;
try
ini.ReadSection(NombreSeccion,SL);
for k:=0 to SL.count-1 do 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); if pinfo<>nil then
begin
Valor:=ini.ReadString(NombreSeccion,SL[K],'');
if Valor<>'' then
begin
if NombreSubPropiedad='' then
SetPropValue(Componente,NombrePropiedad,valor) else
begin
SubObjeto:=GetObjectProp(Componente,pinfo.Name); if GetPropinfo(SubObjeto,NombreSubPropiedad)<>nil then
SetPropValue(SubObjeto,NombreSubPropiedad,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;