Link to home
Start Free TrialLog in
Avatar of shrldu
shrldu

asked on

Enter and DBEdit problem

I have a form with a couple of DBEdits, DBMemos and other DB controls. It is an edit form with a button which posts the changes to the edited record.
In OnKeyPress event I have the code to deal with Enter:

if(Key = #13) then
begin
  Key := #0;
  Perform(WM_NEXTDLGCTL, 0, 0);
end;

When Enter key is pressed on any DB control different than DBEdit the FormKeyPress is called and the next control is focused, but when the Enter is pressed on any of DBEdit controls the OnClick event of my button is called and I'm not able to say why it happens.

Thank you


Avatar of simonet
simonet
Flag of Brazil image

Set the FORM's KeyPreview property to true and make sure that the above code (the one oyu posted) is in the Form's OnKeyPress event, not in each component's OnKeyPress.

Yours,

Alex
you connect some Dbedit's onenter event to your button's onclickevent handle?
Avatar of shrldu
shrldu

ASKER

Simonet,
FORM's KeyPreview property _is_ set to true. The code _is_ in the Form's OnKeyPress event, not in _any_ component's OnKeyPress event. That's what make me crazy about the situation.

Menxin,
Non, I do not.

I can only add that all that is put on a page of a PageControl.


why do you not debug it with step over?
it can help you to find the reason.
Avatar of shrldu

ASKER

Well, I did. Immediately after pressing Enter key in any of my DBEdit controls I am in OnClick event of my button. That's the reason of my desperation. The worse is that it happens only on that one form - others, with similar set of components, work OK. One of the differences is that I have also ActionList on that form - but in no connection with Enter key or my button key, of course. Perhaps there is some side effect of my error but I have no idea how to get to it when the debugger simply takes me to OnClick event of the button instead of going to OnKeyPress event.
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shrldu

ASKER

Hi Kretzschmar,

I'm ashamed having to tell that it was that. I'm going to accept your answer of course - could you comment, please, on why it works like that only in DBEdit, not in DBMemo, for instance?

Great thanks!
Avatar of shrldu

ASKER

Hi Kretzschmar,

I'm ashamed having to tell that it was that. I'm going to accept your answer of course - could you comment, please, on why it works like that only in DBEdit, not in DBMemo, for instance?

Great thanks!
If all else fails,

you can deactivate Button using OnEnter
of DBEdit and activate Button as last
step in OnKeyPress event.

I know, this is a really unusual idea,
but it could do what you want.
hmm, a C-grade :-(

by a dbmemo, i guess, a enter key is normally send to it  to perform a line-break in the memo-text
(i guess this will be never possible now)

glad to helped you ;-)

meikl