Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Using Enter instead of Tab in edit controls.

Posted on 1999-01-22
Medium Priority
Last Modified: 2010-05-18
I have just started using D4 - a leap from D1.  I want to make edit controls respond to the Enter key instead of Tab to move between controls on a form.  In D1 I used the following code:

procedure TEnterEdit.KeyPress(var Key: Char);
   MYForm: TForm;

   if Key = #13 then
       MYForm := GetParentForm( Self );
       if not (MYForm = nil ) then
           SendMessage(MYForm.Handle, WM_NEXTDLGCTL, 0, 0);
       Key := #0;

   if Key <> #0 then inherited KeyPress(Key);


When I tried to compile the component under D4 I got an error telling me that I couldn't use the MyForm variable because of a difference with TCustomForm.

What do I need to change to get the component to work under D4?
Question by:jdthedj
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 17

Expert Comment

ID: 1362905
this page:

gives you the code from borland about using enter as tab,maybe of some help to you but im not sure
Regards Barry
LVL 20

Expert Comment

ID: 1362906
Or you can use this:

procedure SimulateKey(lhwnd: HWND; key: char);
var repeatcount, scancode, contextcode, previouskeystate, transitionstate, lparam: integer;
  repeatcount:=1; scancode:=VkKeyScan(key); contextcode:=0;
  previouskeystate:=0; transitionstate:=0;
  lparam:=repeatcount or (scancode shl 16) or (contextcode shl 29) or
      (previouskeystate shl 30) or (transitionstate shl 31);
  PostMessage(lhwnd, WM_KEYDOWN, ord(key), lparam);
  previouskeystate:=1; transitionstate:=1;
  lparam:=repeatcount or (scancode shl 16) or (contextcode shl 29) or
      (previouskeystate shl 30) or (transitionstate shl 31);
  PostMessage(lhwnd, WM_KEYUP, ord(key), lparam);

procedure TEnterEdit.KeyPress(var Key: Char);
  if Key=#13 then begin
  end else inherited;

Regards, Madshi.
LVL 10

Accepted Solution

viktornet earned 200 total points
ID: 1362907
Here is how to do it...

if key = #13 then
  Perform(WM_NEXTDLGCTL, 0, 0);

That;s need for anything else...

LVL 10

Expert Comment

ID: 1362908
oh I didn;t see it was for a component.. Ok, here is how it would be for a component...

   procedure TEnterEdit.KeyPress(var Key: Char);
      if key = #13 then
              Application.MainForm.Perform(WM_NEXTDLGCTL, 0, 0);

That's all :))

Author Comment

ID: 1362909
Hi to Madshi, Inthe, and Viktornet

Tahnks a lot for the help.

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question