Solved

Using Enter instead of Tab in edit controls.

Posted on 1999-01-22
5
162 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
[X]
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
5 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 1362905
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
ID: 1362906
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
ID: 1362907
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
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);
   begin
      if key = #13 then
              Application.MainForm.Perform(WM_NEXTDLGCTL, 0, 0);
   end;

That's all :))
0
 
LVL 3

Author Comment

by:jdthedj
ID: 1362909
Hi to Madshi, Inthe, and Viktornet

Tahnks a lot for the help.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 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