Board index » delphi » Changing ENTER as TAB in edit controls - Odd behaviors

Changing ENTER as TAB in edit controls - Odd behaviors

I'm using the new and improved Delphi 5. I have a client that wants a
standard edit window with some dbEdit controls.

Using a TEdit control to filter the table the user wants to use the
ENTER key to move from field to field.

I have tried the following examples to get this to work:

In the Form's OnKeyDown event (KeyPreview on)

   if (key=vk_Return) then
      if (Shift = []) then
          SelectNext(ActiveControl,True,True)
      else if (Shift = [ssShift]) then
          SelectNext(ActiveControl,False,True);

When I hit enter from the TEdit control I move to the first DbEdit
control just fine but after entering data and hitting ENTER I go NO
WHERE!

Then I tried:

Procedure TfrmDataEntry.CMDialogKey( Var Msg: TWMKey );
Begin
   If NOT (ActiveControl Is TButton) Then
      If Msg.Charcode = 13 Then
         Msg.Charcode := 9;
   inherited;
End;

With this procedure as part of the form's PRIVATE declaration. NOTHING
from this, either.

Is there something WIERD about DBEdit controls that trashes the enter
key?

Does anyone have any suggestions (other than getting the user to
concede using the TAB key instead, of course...this is NOT an option
on this program...)

Thanks for any help!

Bill

Bill Artemik
Programmer / Analyst
Droste Consultants, Inc.
b...@droste1.com

"There are THREE kinds of people in the world...
      Those that can count and those that can't."

 

Re:Changing ENTER as TAB in edit controls - Odd behaviors


On 4 Oct 1999 08:17:02 -0500, b...@droste1.com (Bill Artemik) wrote:

Quote
>I'm using the new and improved Delphi 5. I have a client that wants a
>standard edit window with some dbEdit controls.

>Using a TEdit control to filter the table the user wants to use the
>ENTER key to move from field to field.

Not exactly a "standard" edit window <grin> -- not using the Enter key to
navigate between controls.

Quote
>I have tried the following examples to get this to work:

>In the Form's OnKeyDown event (KeyPreview on)

>   if (key=vk_Return) then
>      if (Shift = []) then
>          SelectNext(ActiveControl,True,True)
>      else if (Shift = [ssShift]) then
>          SelectNext(ActiveControl,False,True);

>When I hit enter from the TEdit control I move to the first DbEdit
>control just fine but after entering data and hitting ENTER I go NO
>WHERE!

[...]

Have you verified that the TDBEdit is associated with that event handler?
That is, is its OnKeyPress event property assigned to the procedure in
which the keystrokes are intercepted to navigate to the next control? Have
you set a break point in the event handler to what where the code execution
goes as you step through that portion of the application? Does execution
ever even go into the event handler.

Personally, I use code like that below to do this. One thing I do in the
routine below that you do not do at all is neutralize the keystroke after
it has been intercepted and used.

  procedure Form1.FormKeyPress(Sender: TObject; var Key: Char);
  begin
    if (Ord(Key) = VK_RETURN { the Enter key }) then begin
      { Always nullify keystrokes handled }
      Key := #0;
      { Signal to move focus to next control }
      Perform(WM_NEXTDLGCTL, 0, 0);
    end;
  end;

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Steve Koterski              "Health nuts are going to feel stupid someday,
Felton, CA                  lying in hospitals dying of nothing."
                                                              -- Redd Foxx

Other Threads