Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How would I implement going to next component on a form when I press CR



Permlink Replies: 5 - Last Post: Feb 21, 2018 2:25 AM Last Post By: Daniel Fields
Ed Brazell

Posts: 8
Registered: 12/16/04
How would I implement going to next component on a form when I press CR
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 16, 2018 8:22 AM
I have a input form and would like to be able to go from one editbox to the next based on the TabOrder like I would do using a regular editbox and OnKeyPress. I could use OnSubmit but I don't want to actually submit anything.

Thanks,

Ed
Daniel Fields

Posts: 622
Registered: 11/29/04
Re: How would I implement going to next component on a form when I press CR
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 17, 2018 3:57 PM   in response to: Ed Brazell in response to: Ed Brazell
You have to use the OnAsyncKeyPress event for each control on the form. You can create one event an use it for every control. The code below works for a simple form with 3 edit controls on it.

procedure TFormLogin.IWEdit1AsyncKeyPress(Sender: TObject; EventParams: TStringList);
begin
  if EventParams.Values['which']='13' then  //some 3rd party controls use 'key' instead of 'which'
  begin
    if Sender.Equals(IWEdit1) then
      self.SetActiveControl(IWEdit2)
    else if Sender.Equals(IWEdit2) then
      self.SetActiveControl(IWEdit3);
  end;
end;
Ed Brazell

Posts: 8
Registered: 12/16/04
Re: How would I implement going to next component on a form when I press CR
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 20, 2018 8:05 AM   in response to: Daniel Fields in response to: Daniel Fields
Thank You

Daniel Fields wrote:
You have to use the OnAsyncKeyPress event for each control on the form. You can create one event an use it for every control. The code below works for a simple form with 3 edit controls on it.

procedure TFormLogin.IWEdit1AsyncKeyPress(Sender: TObject; EventParams: TStringList);
begin
  if EventParams.Values['which']='13' then  //some 3rd party controls use 'key' instead of 'which'
  begin
    if Sender.Equals(IWEdit1) then
      self.SetActiveControl(IWEdit2)
    else if Sender.Equals(IWEdit2) then
      self.SetActiveControl(IWEdit3);
  end;
end;
Eitan Arbel

Posts: 508
Registered: 2/24/13
Re: How would I implement going to next component on a form when I press CR
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 20, 2018 10:36 AM   in response to: Daniel Fields in response to: Daniel Fields
Hi Daniel,.
i think it was you who taught me about "if EventParams.Values['which']='13'" a few years ago... :D

i use this :
procedure TFormLogin.IWEdit1AsyncKeyPress(Sender: TObject; EventParams: TStringList);
begin
  if EventParams.Values['which']='13' then IWEdit2.SetFocus;
end;

what is the difference between self.SetActiveControl(IWEdit2); and IWEdit2.SetFocus; please ?

Chad Hower

Posts: 613
Registered: 3/2/07
Re: How would I implement going to next component on a form when I press CR
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 20, 2018 3:13 PM   in response to: Eitan Arbel in response to: Eitan Arbel
On 2/20/2018 2:36 PM, Eitan Arbel wrote:
what is the difference between self.SetActiveControl(IWEdit2); and IWEdit2.SetFocus; please ?

Off the top of my head, the self. in this case is the page and the 2
calls are identical and if I recall correctly one calls the other and
they are just syntactic sugar.

Daniel Fields

Posts: 622
Registered: 11/29/04
Re: How would I implement going to next component on a form when I press CR
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 21, 2018 2:25 AM   in response to: Eitan Arbel in response to: Eitan Arbel
I thought this question felt familiar. I have not found any difference between SetFocus and SetActiveControl, performance wise. I think I use them both. I go with whichever one I recall first.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02