Tab/Enter em todos Forms

Delphi

22/04/2004

Estou utilizando o seguinte código para avançar campos com o ENTER:
procedure TF_VslCli01.FormKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then
begin
Key := 0;
SendMessage(Self.Handle, Wm_NextDlgCtl,0,0);
end;
end;

Gostaria de saber se tem uma forma de implementar em todo o meu projeto ou terei que repetir esta rotina em todos os forms que eu criar?

Desde já agradeço qualquer ajuda.

Rony Lee


Ronylee

Ronylee

Curtidas 0

Respostas

Weverton

Weverton

22/04/2004

:arrow: Vc pode fazer de duas formas:

1 - Criar um form, implementar esse código no OnKeyPress e criar os outros forms herdando desse primeiro;
2 - Colocar um componente ApplicationEvents no form principal da aplicação e fazer o tratamento no evento OnMessage.


GOSTEI 0
Ronylee

Ronylee

22/04/2004

Weverton acho que a segunda opção seria a mais adequada (mais profissional também), porém não sei como fazer, pode me ajudar?


GOSTEI 0
Eniorm

Eniorm

22/04/2004

No form principal crie este procedimento:

procedure TSimoFormPrincipal.ProcessaMsg(var Msg: TMsg;
  var Handler: Boolean);
begin
     if (Msg.message = WM_KEYDOWN) then
        if not (Screen.ActiveControl is TCustomMemo) and
           not (Screen.ActiveControl is TButtonControl) then begin
             if not (Screen.ActiveControl is TCustomControl) then begin
                if (Msg.wParam = VK_Down) and
                   not(Screen.ActiveControl is TListBox) and
                   not(Screen.ActiveControl is TComboBox) then
                   Msg.wParam:= VK_Tab;
                if (Msg.wParam = VK_UP) and
                   not(Screen.ActiveControl is TListBox) and
                   not(Screen.ActiveControl is TComboBox) then begin
                   Msg.wParam:= VK_CLEAR;
                   Screen.ActiveForm.Perform(WM_NextDlgCtl,1,0);
                end;
                if (Msg.wParam = VK_Escape) and
                  not (Screen.ActiveForm is TSimoformPrincipal) then
                   Screen.ActiveForm.Close;
             end;
             if (Msg.wParam = VK_Return) then
                Msg.wParam:= VK_Tab;
        end;
end;


Agora no OnCreate do form principal:
Application.OnMessage := ProcessaMsg;



GOSTEI 0
POSTAR