Solved

Using Enter instead of Tab in edit controls.

Posted on 1999-01-22
5
158 Views
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);
var
   MYForm: TForm;
begin

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

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

end;

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?
0
Comment
Question by:jdthedj
5 Comments
 
LVL 17

Expert Comment

by:inthe
Comment Utility
this page:
http://www.inprise.com/delphi/news/zd/1998/oct98/

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

Expert Comment

by:Madshi
Comment Utility
Or you can use this:

procedure SimulateKey(lhwnd: HWND; key: char);
var repeatcount, scancode, contextcode, previouskeystate, transitionstate, lparam: integer;
begin
  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);
end;

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

Regards, Madshi.
0
 
LVL 10

Accepted Solution

by:
viktornet earned 50 total points
Comment Utility
Here is how to do it...

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

That;s all...no need for anything else...

-Viktor
--Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
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);
   begin
      if key = #13 then
              Application.MainForm.Perform(WM_NEXTDLGCTL, 0, 0);
   end;

That's all :))
0
 
LVL 3

Author Comment

by:jdthedj
Comment Utility
Hi to Madshi, Inthe, and Viktornet

Tahnks a lot for the help.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now