Fórum Dúvida em rotina que troca cor de edits #374830
12/09/2009
0
Estou testando a rotina abaixo para trocar a cor de edits, dbedits, etc em todo o projeto:
procedure TFormPrincipal.ColorControl(Sender: TObject); var Cor: TColor; I: integer; begin With Screen.ActiveForm do begin for I:= 0 to ComponentCount -1 do begin if (Components[I] is TCustomEdit) then begin if (Components[I] as TCustomEdit).Focused then Cor:= clActiveBorder else Cor:= clWindow; AtribuiProp(Components[I], ´Color´, IntToStr(Cor)); end; end; end; end; // Atibui propriedade ao componente, dado seu valor como string procedure TFormPrincipal.AtribuiProp(Comp: TComponent; const PropName: string; Val: string); var PInfo: PPropInfo; begin // Pega informações de tipo da propriedade PInfo := GetPropInfo(Comp.ClassInfo, PropName); // Achou? if PInfo <> nil then begin // Trata conforme o tipo case PInfo^.Proptype^.Kind of tkInteger: SetOrdProp(Comp, PInfo, StrToInt(Val)); tkChar, tkWChar: SetOrdProp(Comp, PInfo, ord(Val[1])); tkEnumeration: SetOrdProp(Comp, PInfo, GetEnumValue(PInfo^.PropType^, Val)); tkFloat: SetFloatProp(Comp, PInfo, StrToFloat(Val)); tkString, tkLString, tkWString: SetStrProp(Comp, PInfo, Val); tkVariant: SetVariantProp(Comp, PInfo, Val); tkInt64: SetInt64Prop(Comp, PInfo, StrToInt64(Val)); end;//case end;//if end;
Gostaria de alterar a mesma para que não mude a cor de componentes que estão readonly = true ou q estejam com a cor clinfoBk.
Já tentei algumas coisas mas não consegui e por isso peço a ajuda dos colegas do forum.
Obrigado,
Marcello.
Marcello
Curtir tópico
+ 0Posts
12/09/2009
Afarias
Entretanto, problema: ReadOnly é protegido na classe base (TCustomEdit) -- pelo menos no D7.
Bom, neste caso, pra evitar ficar ´brincando´ com RTTI só por causa disso, eu apenas mudaria a TAG dos componentes ReadOnly para 1 e usaria o seguinte código:
procedure TFormPrincipal.ColorControl(Sender: TObject); var I: integer; begin with Screen.ActiveForm do begin for I:= 0 to ComponentCount-1 do begin if (Components[I] is TCustomEdit) then with (Components[I] as TCustomEdit) do begin if (Color<>clInfoBk) and (Tag=0) then begin if Focused then Color := clActiveBorder else Color := clWindow; end; end; end; end; end;
T+
Gostei + 0
12/09/2009
Dbergkamps10
Eu faço assim para trocar a cor dos componentes q recebem o foco:
Na seção type, boto o seguinte:
TMeuComponente = class(TControl) public property Color;
depois, declaro nas procedures:
procedure FocoAlterado(Sender: TObject);
{ Private declarations }
public
end;
{ Public declarations }
const
CorSemFoco = clWindow;
CorComFoco = $00EFD3C6;
depois, o codigo da procedure:
procedure TFMCadCargos.FocoAlterado(Sender: TObject); begin if Componente <> nil then try begin // TMeuComponente(Componente).Color := CorSemFoco; TMeuComponente(Componente).Color := CorAnterior; TMeuComponente(Componente).Font.Style:= []; end; except end; if Screen.ActiveForm.ActiveControl is TWinControl then try CorAnterior := TMeuComponente(Screen.ActiveForm.ActiveControl).Color; TMeuComponente(Screen.ActiveForm.ActiveControl).Color := CorComFoco; TMeuComponente(Screen.ActiveForm.ActiveControl).Font.Style:= [fsbold]; Componente := Screen.ActiveForm.ActiveControl; except end; end;
no evento OnDestroy e OnCreate de cada form, botar:
procedure TFMCadCargos.FormDestroy(Sender: TObject); begin Screen.OnActiveControlChange := nil; end; procedure TFMCadCargos.FormCreate(Sender: TObject); begin Screen.OnActiveControlChange := FocoAlterado; end;
Gostei + 0
12/09/2009
Marcello
Esta rotina esta em meu form principal e altera as cores em todos os forms como estava originalmente. Pra mim é suficiente um teste na cor clInfoBk.
dbergkamps10, agradeço a dica, mas gostaria de continuar com a rotina q estou usando, pois só tive q implementar código no form principal.
Marcello.
Gostei + 0
12/09/2009
Dbergkamps10
como vc ja deve ta com o projeto em andamento, fica trabalhoso trocar mesmo.
att
dalton
Gostei + 0
13/09/2009
Marcello
Resolvi em definitivo o problema através de uma dica do marcossalles que encontrei no seguinte endereço:
[url]http://www.activedelphi.com.br/forum/viewtopic.php?t=50426[/url]
Agradeço a todos pela ajuda.
Marcello.
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)