Ver Mensaje Individual
  #3  
Antiguo 25-01-2012
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola.

Con Delphi 7 y superior podrías hacer algo como:
Código Delphi [-]
...
implementation

uses TypInfo;

procedure TForm1.CambiarPropiedad(const AName, AProperty, AValue: string);
var
  PInfo: PPropInfo;
  TC: TComponent;
begin
  TC:= FindComponent(AName);
  PInfo:= GetPropInfo(TC.ClassInfo, AProperty);
  if PInfo <> nil then
  begin
    case PInfo^.Proptype^.Kind of
      tkString, tkLString: SetStrProp(TC, PInfo, AValue);
      tkInteger: if (PInfo^.PropType^.Name = 'TColor') then
                   SetOrdProp(TC, PInfo, StringToColor(AValue))
                 else if (PInfo^.PropType^.Name = 'TCursor') then
                   SetOrdProp(TC, PInfo, StringToCursor(AValue))
                 else
                   SetOrdProp(TC, PInfo, StrToInt(AValue));
      tkEnumeration: try
                       if (PInfo^.PropType^ = TypeInfo(System.Boolean)) then
                         SetOrdProp(TC, PInfo, StrToInt(AValue))
                       else
                         SetOrdProp(TC, PInfo, StrToInt(AValue));
                      except
                         raise;
                      end;
    end;
  end;
end;

Ejemplo de uso:
Código Delphi [-]
  CambiarPropiedad('edPuerto', 'Text', 'Hola');
  CambiarPropiedad('edPuerto', 'Color', 'clLime');
  CambiarPropiedad('edPuerto', 'Cursor', 'crHandPoint');
  ...

Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....

Última edición por ecfisa fecha: 25-01-2012 a las 19:25:09.
Responder Con Cita