Creo que para eso puedes utilizar RTTI.
Te acnsejo que busques entre los fuentes de Delphi la unit llamada
TypInfo.pas y le eches un vistazo (normalmente en el directorio ...\sources\rtl\common de Delphi)
Verás que puedes encontrar procedimientos interesantes.
Yo utilizo el siguiente:
Código Delphi
[-]
function SetPropAsString(AObj: TObject; const PropName, Value: String):Boolean;
var
PInfo: PPropInfo;
Begin
PInfo := GetPropInfo(AObj.ClassInfo, PropName);
Result := PInfo <> nil;
if (Result) then begin
if (PInfo^.Proptype^.Kind = tkString) or
(PInfo^.Proptype^.Kind = tkLString) then begin
SetStrProp(AObj, PInfo, Value);
end
else if (PInfo^.Proptype^.Kind = tkInteger) then begin
if (PInfo^.PropType^.Name = 'TColor') then begin
SetOrdProp(AObj, PInfo, StringToColor(Value));
end
else if (PInfo^.PropType^.Name = 'TCursor') then begin
SetOrdProp(AObj, PInfo, StringToCursor(Value));
end
else begin
SetOrdProp(AObj, PInfo, StrToInt(Value));
end;
end
else if (PInfo^.Proptype^.Kind = tkEnumeration) then begin
try
if (PInfo^.PropType^ = TypeInfo(System.Boolean)) then begin
SetOrdProp(AObj, PInfo, StrToInt(Value));
end
else begin
SetOrdProp(AObj, PInfo, StrToInt(Value));
end;
except
raise;;
end;
end
else begin
Result := False;
end;
end
else begin
Result := False;
end;
end;
Para usarlo puedes utilizar:
Código Delphi
[-]
SetPropAsString(Edit1, 'Color', 'clRed');
SetPropAsString(Label1, 'Color', 'clRed');
...