Fórum Problemas na implementação do evento OnkeyDown.. #194283

11/11/2003

0

Boa tarde a todos..
Estou implementando em meus sistemas algumas teclas de funções, e para isto estou utlizando o evento OnKeyDown, construi uma funcão genérica que chamo neste evento, da seguinte forma..

procedure TProdutoForm.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
[b:24e3d56a0e]EnterAsTab(ProdutoForm,Key,INavigator)[/b:24e3d56a0e]; //esta é funcão genérica.
end;

As teclas que processo nesta funcão são:

F6 -> INCLUI
F8 -> EXCLUI
F2 -> EDITA
F7 -> GRAVA
F9 ->CANCELA
F4 -> IMPRIME
F3 -> PESQUISA
F5 -> FILTRA
F10 ->SAI
Estou utilizando o componente navigator da InfoPower, mas poderia ser o do próprio delphi e passo para a função o form, a telca e o navigator , da seguite forma..
[b:24e3d56a0e]EnterAsTab(ProdutoForm,Key,INavigator);[/b:24e3d56a0e] no evento onKeyDown

O problema é que as vezes quando pressiono alguma das teclas de funcão nada ocorre, tenho que pressiona-la duas vezes para que ocorra o evento, e as vezes também ocorre de eu estar com o foco em um determinado componente, uma dbgrid por exemplo, e pressiono a tecla F6, o foco não sai do componente que estou, no caso o F6 inclui, então mando o foco para o Código do produto assim DBEditProcod.Setfocus, e nada acontece, ele abre um registro em branco mas o foco não muda.

A funcão em questão é esta:
procedure EnterAsTab(Frm:TForm; Var Key:Word;const Nav:TwwDBNavigator);
var Dummy : TMsg ;
begin
if (Key in [VK_F2..VK_F10]) then
begin
if (Key = VK_F2) and (Nav.Buttons.Items[6].Visible) then
Nav.Buttons.Items[6].Click; // Editar

if (Key = VK_F3) and (Nav.Buttons.Items[10].Visible) then
Nav.Buttons.Items[10].Click; // Pesquisar

if (Key = VK_F4) and (Nav.Buttons.Items[9].Visible) then
Nav.Buttons.Items[9].Click; // Imprimir

if (Key = VK_F5) and (Nav.Buttons.Items[11].Visible) then
Nav.Buttons.Items[11].Click; // Filtrar

if (Key = VK_F6) and (Nav.Buttons.Items[4].Visible) then

Nav.Buttons.Items[4].Click; // Incluir

if (Key = VK_F7) and (Nav.Buttons.Items[7].Visible) then
Nav.Buttons.Items[7].Click; // Gravar

if (Key = VK_F8) and (Nav.Buttons.Items[5].Visible) then
Nav.Buttons.Items[5].Click; // Excluir

if (Key = VK_F9) and (Nav.Buttons.Items[8].Visible) then
Nav.Buttons.Items[8].Click; // Cancelar

if (Key = VK_F10) and (Nav.Buttons.Items[12].Visible) then
Nav.Buttons.Items[12].Click; // Sair
end;

if ((Key = VK_RETURN) and not (Frm.ActiveControl is TDBMemo)) then
begin
PeekMessage(Dummy, Frm.Handle, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE) ;
if not ((Frm.ActiveControl is TDBGrid)
or (Frm.ActiveControl is TwwDBGrid)) then
begin
Frm.Perform(WM_NEXTDLGCTL, 0, 0);
end;
if (Frm.ActiveControl is TDBGrid) then
begin
with TDBGrid(Frm.ActiveControl) do
begin
if selectedIndex < (fieldcount -1) then
selectedindex := selectedindex +1
else
selectedindex := 0;
end;
end;
end;
if ((Key = VK_RETURN) and (Frm.ActiveControl is TDBMemo)) then
Frm.Perform(WM_NEXTDLGCTL, 0, 0);
end;

Como podem notar estou utilizando o navigator do infopower, mas também já testei com o navigator do delphi, que ficaria assim
[b:24e3d56a0e] if (Key = VK_F6) then
Nav.Btnclick(nbInsert); // Incluir[/b:24e3d56a0e]
Se alguém de vocês já tentantaram ou implementaram teclas de funções com componentes de dados poder me dar uma dica desde já agradeço.

Obrigado

Fausto


Faustoalves

Faustoalves

Responder

Posts

11/11/2003

Faustoalves

por acaso a propriedade KeyPreview do FORM já está como True? Se não, altere-a para True.


Se a propriedade não estivesse setada para true, nada funcionaria...


Responder

Gostei + 0

11/11/2003

Marcelo Saviski

Se colocar em vez de OnKeyDown em OnKeyPress não funciona tambem?


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar