[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 839
  • Last Modified:

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


0
shrldu
Asked:
shrldu
  • 4
  • 2
  • 2
  • +2
1 Solution
 
simonetCommented:
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
0
 
men xinCEOCommented:
you connect some Dbedit's onenter event to your button's onclickevent handle?
0
 
shrlduAuthor Commented:
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.


0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
men xinCEOCommented:
why do you not debug it with step over?
it can help you to find the reason.
0
 
shrlduAuthor Commented:
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.
0
 
kretzschmarCommented:
hi shrldu,

if the default-property of this button is true,
then set it to false and try again.

meikl
0
 
shrlduAuthor Commented:
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!
0
 
shrlduAuthor Commented:
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!
0
 
DGNCommented:
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.
0
 
kretzschmarCommented:
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
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 4
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now