Enter to tab

Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Feb 2007
Posts: 53
Reputation: edouard89 is an unknown quantity at this point 
Solved Threads: 2
edouard89's Avatar
edouard89 edouard89 is offline Offline
Junior Poster in Training

Enter to tab

 
0
  #1
Mar 1st, 2007
First of I would like to say hi to everyone as I am new to this forum.

My problem is this. Can I some how use the [ENTER] key instead of the [TAB] key to skip from field to field? Any help would be greatly apreciated.

Thank you.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 171
Reputation: radu84 is an unknown quantity at this point 
Solved Threads: 16
radu84 radu84 is offline Offline
Junior Poster

Re: Enter to tab

 
0
  #2
Mar 2nd, 2007
place this code in the first edit onkeydown event

procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case key of
13:edit2.SetFocus;
end;
end;


best regards,
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: Enter to tab

 
0
  #3
Mar 4th, 2007
Another way of trapping the Enter key is by using the form's KeyPreview property set to true. Then on the Form's onKeyPress event do this:

Pascal and Delphi Syntax (Toggle Plain Text)
  1. procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
  2. var
  3. i:integer;
  4. tbOrder:Integer;
  5. nextComponent: TComponent;
  6.  
  7. function getControlForNextTabOrder: TComponent;
  8. var iThisTab:Integer;
  9. n:Integer;
  10. begin
  11. result := nil;
  12. iThistab := ActiveControl.TabOrder;
  13. for n := 0 to ComponentCount -1 do
  14. if TWinControl(Components[n]).TabOrder = iThisTab +1 then
  15. begin
  16. result := Components[n];
  17. break;
  18. end;
  19. end;
  20. begin
  21. if Key = #13 then
  22. begin
  23. nextComponent := getControlForNextTabOrder();
  24. if (nextComponent <> nil) then
  25. begin
  26. ActiveControl := TWinControl(nextComponent);
  27. Key := #0; // prevent Key from propogating any further
  28. end;
  29. end;
  30. end;

Be aware that TButtons and such will not throw this event handler. So the focus can not move to the next control when this type of component has focus. Memo boxes will get focus, but you have to use Shift+Enter for new lines in the memo. You can obviously curcumvent some of this behavior in the onKeyPress event, by examining the currently ActiveControl type or name.

This example obeys the TabOrder, and prevents you from writing a KeyPress event handler for each control that you want this behaviour.

--Jerry
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 53
Reputation: edouard89 is an unknown quantity at this point 
Solved Threads: 2
edouard89's Avatar
edouard89 edouard89 is offline Offline
Junior Poster in Training

Re: Enter to tab

 
0
  #4
Mar 4th, 2007
Thanks both of you for your help I will try it out and see if it preforms the way I want it to.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 171
Reputation: radu84 is an unknown quantity at this point 
Solved Threads: 16
radu84 radu84 is offline Offline
Junior Poster

Re: Enter to tab

 
0
  #5
Mar 5th, 2007
also you can try to hook up the windows key messages. in this way you can handle all the keys include TAB.

best regards,
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Pascal and Delphi
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC