Array
(
)

como usar o evento onactivate

Helder Andr
   - 12 ago 2004

Nao consigo usar esse evento, feito para mudar a cor de fundo
do componente que tem o foco.No comeco funciona beleza.
Checa um ponto onde se eu nao
usar o try except end ele da operacao ilegal, e se eu usar o
try except end ele nao consegue mudar a cor do componente
onde esta o erro?

veja trecho do programa

private
{ Private declarations }
procedure AppException(Sender: TObject; E: Exception);
public
ComponAnt: TComponent;
procedure ControlChange(Sender: TObject);
end;


procedure Tfrmmenu.ControlChange(Sender: TObject);
begin
if not frmmenu.k_edicao then exit; // coloquei pois estava dando pau

try // coloque para evitar a mensagem de erro operacao ilegal

if Assigned(frmmenu.ComponAnt) then
begin
if (frmmenu.ComponAnt is TEdit) then TEdit(frmmenu.ComponAnt).Color := $00FAEBD1; // cor com foco
if (frmmenu.ComponAnt is TdbEdit) then TdbEdit(frmmenu.ComponAnt).Color := $00FAEBD1; // cor com foco
if (frmmenu.ComponAnt is TDBCheckBox) then TDBCheckBox(frmmenu.ComponAnt).Color := $00FAEBD1; // cor com foco
if (frmmenu.ComponAnt is TDBComboBox) then TDBComboBox(frmmenu.ComponAnt).Color := $00FAEBD1; // cor com foco
if (frmmenu.ComponAnt is TDBmemo) then TDBmemo(frmmenu.ComponAnt).Color := $00FAEBD1; // cor com foco
if (frmmenu.ComponAnt is TSpinEdit) then TSpinEdit(frmmenu.ComponAnt).Color := $00FAEBD1; // cor com foco
if (frmmenu.ComponAnt is TCurrencyEdit) then TCurrencyEdit(frmmenu.ComponAnt).Color := $00FAEBD1; // cor com foco
if (frmmenu.ComponAnt is Tmemo) then Tmemo(frmmenu.ComponAnt).Color := $00FAEBD1; // cor com foco
if (frmmenu.ComponAnt is Tdateedit) then Tdateedit(frmmenu.ComponAnt).Color := $00FAEBD1; // cor com foco
if (frmmenu.ComponAnt is TComboBox) then TComboBox(frmmenu.ComponAnt).Color := $00FAEBD1; // cor com foco
if (frmmenu.ComponAnt is TDBLookupComboBox) then TDBLookupComboBox(frmmenu.ComponAnt).Color := $00FAEBD1; // cor com foco
if (frmmenu.ComponAnt is TmaskEdit) then TmaskEdit(frmmenu.ComponAnt).Color := $00FAEBD1; // cor com foco
end;

if (screen.activecontrol is TEdit) or
(screen.activecontrol is TDBEdit) or
(screen.activecontrol is TDBCheckBox) or
(screen.activecontrol is TDBComboBox) or
(screen.activecontrol is TDBmemo) or
(screen.activecontrol is TSpinEdit) or
(screen.activecontrol is TCurrencyEdit) or
(screen.activecontrol is Tmemo) or
(screen.activecontrol is Tdateedit) or
(screen.activecontrol is TComboBox) or
(screen.activecontrol is TDBLookupComboBox) or
(screen.activecontrol is TmaskEdit) then
begin
if (screen.activecontrol is TEdit) then TEdit(screen.activecontrol).Color := clinfobk; // cor com foco
if (screen.activecontrol is TdbEdit) then TdbEdit(screen.activecontrol).Color := clinfobk; // cor com foco
if (screen.activecontrol is TDBCheckBox) then TDBCheckBox(screen.activecontrol).Color := clinfobk; // cor com foco
if (screen.activecontrol is TDBComboBox) then TDBComboBox(screen.activecontrol).Color := clinfobk; // cor com foco
if (screen.activecontrol is TDBmemo) then TDBmemo(screen.activecontrol).Color := clinfobk; // cor com foco
if (screen.activecontrol is TSpinEdit) then TSpinEdit(screen.activecontrol).Color := clinfobk; // cor com foco
if (screen.activecontrol is TCurrencyEdit) then TCurrencyEdit(screen.activecontrol).Color := clinfobk; // cor com foco
if (screen.activecontrol is Tmemo) then Tmemo(screen.activecontrol).Color := clinfobk; // cor com foco
if (screen.activecontrol is Tdateedit) then Tdateedit(screen.activecontrol).Color := clinfobk; // cor com foco
if (screen.activecontrol is TComboBox) then Tcombobox(screen.activecontrol).Color := clinfobk; // cor com foco
if (screen.activecontrol is TDBLookupComboBox) then TDBLookupComboBox(screen.activecontrol).Color := clinfobk; // cor com foco
if (screen.activecontrol is TmaskEdit) then TmaskEdit(screen.activecontrol).Color := clinfobk; // cor com foco
frmmenu.ComponAnt := screen.activecontrol;
end;
except
end;
end;

ativo no evento

procedure Tfrmfornece.FormActivate(Sender: TObject);
begin
Screen.OnActiveControlChange := frmmenu.ControlChange;
end;

desativo no evento

procedure Tfrmfornece.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if dm.IBTransaction1.InTransaction then dm.IBTransaction1.Commit;
Screen.OnActiveControlChange := nil;
action := cafree;
end;

alguem pode me ajudar


Aersoftware
   - 12 ago 2004

Helder, o q vc ker é fazer um componente do Form mudar de cor quando tiver o foco ou o proprio form? Se for um componente, nao precisa de tudo isso nao.. basta usar os eventos OnEnter e OnExit do próprio componente em questão..

Exemplo


Citação:
Procedure OnEnter
begin
Componente.color := clGreen;
end;



Citação:
Procedure OnExit
begin
Componente.color := clWindow;
end;


No primeiro o componente fica verde quando receber o foco e o segundo ele fica da cor padrão quando nao tiver mais o foco..



Allan Elias Ramos :roll: