Cita:
Empezado por pborges36
...espero su opinion, comentarios y sugerencias para que vayamos mejorandolo.
|
Código Delphi
[-]
Procedure TBRGFocusAdmin.AplicarColor(Color :TColor; Componente: TWinControl);
begin
try
if (Componente is TCustomEdit) then (Componente as TEdit).Color := Color;
if (Componente is TDateTimePicker) then (Componente as TDateTimePicker).Color:= Color;
if (Componente is TCustomMemo) then (Componente as TMemo).Color:= Color;
if (Componente is TCustomComboBox) then (Componente as TComboBox).Color:= Color;
(Componente as TWinControl).Repaint;
except
end;
end;
Creo que esto se puede optimizar (para cualquier componente que tenga esa propiedad) utilizando RTTI. Lo bueno de esto es que generalizando un poco la siguiente función se puede hacer para cualquier propiedad.
Código Delphi
[-]
procedure TForm1.Button2Click(Sender: TObject);
var
i:Integer;
function ExistProp(Instance: TObject; const PropName: string):Boolean;
var
PropInfo: PPropInfo;
begin
PropInfo := GetPropInfo(Instance, PropName);
Result := not (PropInfo = nil);
end;
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 begin
SetOrdProp(AObj, PInfo, StrToInt(Value));
end;
end
else begin
Result := False;
MessageDlg('''La propiedad '' + PropName + '' no es de tipo String (o un tipo implementado)', mtWarning, [mbOK], 0);
end;
end
else begin
Result := False;
end;
end;
begin
for i := 0 to (Self.ComponentCount - 1) do begin
if ExistProp(Self.Components[i], 'Color') then begin
SetPropAsString(Self.Components[i], 'Color', 'clInfoBk');
end;
end;
end;