Download events Onkeydown and Onexit

Asked

Viewed 2,456 times

0

I have the following code at the events:

Onexit:

procedure TFEqt_Pallet.EdNr_PalletExit(Sender: TObject);
var
 MeuKey: word;
begin
 MeuKey := 13;
 EdNr_PalletKeyDown(EdNr_Pallet,MeuKey,[]); 
end;

Onkeydown:

procedure TFEqt_Pallet.EdNr_PalletKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Ord(key) = 13 then
begin
...
 proximocampo.setfocus;
end;

When I enter the component it is calling the Onexit method twice. How can I resolve this?

  • It is not right to call an event from within another event. Rephrase your logic so that it does not occur.

2 answers

1


When you press the Enter key on Edit, your Keydown precedent perform a number of things and at the end "arrow" the focus on another component, when this occurs, the Onexit Precedent is called and in turn it calls again the Keydown Precedent, so this repetition.

I believe you are doing this because you want to perform a series of procedures when the user presses enter and/or exits Edit.

You should put these procedures in onExit and onKeyDown only the setfocus for the next component.

Example:

Onexit:

procedure TFEqt_Pallet.EdNr_PalletExit(Sender: TObject);
var
 MeuKey: word;
begin
 O aque eu quero que faça.
end;

Onkeydown:

procedure TFEqt_Pallet.EdNr_PalletKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Ord(key) = 13 then
begin
 proximocampo.setfocus;
end;

0

The ideal is not to have control of switching focus within components, leave it to the form. Follow the steps below and improve your source a little

  1. Properly configure the Taborder’s of your components form.
  2. Activate the form Keypreview.
  3. In the form Keydown event put the code:

if Key = VK_RETURN then Perform(WM_NEXTDLGCTL, 0, 0);

Tip: Don’t use focus control on Onexit components. If you are in one component and decide to return in another by clicking with the mouse, the focus will not p where it should. This irritates.

  • I added your code to Keydown, but it still has the same problem, when I use Enter it calls twice Onkeydown and once Onexit.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.