Ver Mensaje Individual
  #7  
Antiguo 23-09-2011
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 38
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.

Aunque no pretende ser código de alto vuelo con el uso de RTTI ( esa taréa se la dejo a Neftalí ), te completé el procedimiento para que contemple algunos tipos más de propiedades. (no podía ser tan haragán...).
Código Delphi [-]
uses TypInfo;

procedure TForm1.SetCtrlsProp(Lista: array of string; AProp,Value: Variant);
var
  i,j: Integer;
  PInfo: PPropInfo;
begin
  for i:= High(Lista) downto Low(Lista) do
  begin
    j:= 0;
    while(j < ControlCount)and(Controls[j].Name <> Lista[i])do Inc(j);
    if(j < ControlCount)and(Controls[j].Name = Lista[i]) then
    begin
      PInfo:= GetPropInfo(Controls[j].ClassInfo, AProp);
      if PInfo <> nil then
      begin
        case PInfo^.PropType^.Kind of
          tkString,tkLString:SetStrProp(Controls[j],Aprop,VarToStr(Value));
          tkInteger: SetOrdProp(Controls[j], AProp, StrToInt(Value));
          tkEnumeration: SetOrdProp(Controls[j], AProp,Value);
          else 
            raise Exception.Create('caso no contemplado');
        end;
      end;
    end;
  end;
end;

Ahora podés hacer por ejemplo:
Código Delphi [-]
  SetCtrlsProp(['Edit1', 'Edit3', 'Edit2'], 'Text', 'NUEVO TEXTO');
  SetCtrlsProp(['DBGrid1', 'DBEdit1', 'DBEdit2'], 'ReadOnly', True);
  SetCtrlsProp(['Edit1', 'Edit2', 'DBGrid1'], 'Color', clYellow);
  SetCtrlsProp(['Edit1'], 'Cursor', crHandPoint);

Un saludo.
__________________
Daniel Didriksen

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

Última edición por ecfisa fecha: 23-09-2011 a las 00:49:26.
Responder Con Cita