Watch, Follow, &
Connect with Us

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


Welcome, Guest
Guest Settings
Help

Thread: FMX How to programmatically move to the next tabstop


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 1 - Last Post: Aug 19, 2015 10:45 AM Last Post By: Francis Silva
Robert [NL] Mit...

Posts: 100
Registered: 5/23/04
FMX How to programmatically move to the next tabstop  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 27, 2015 4:03 AM
Using Delphi XE8 PE FireMonkey (on Windows 7)

I have several TEdit components on my form.

How can I programmatically change focus to the next edit component?

FMX seems not to have a SelectNext method like VCL does.
Francis Silva

Posts: 1
Registered: 2/20/01
Re: FMX How to programmatically move to the next tabstop  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 19, 2015 9:48 AM   in response to: Robert [NL] Mit... in response to: Robert [NL] Mit...
Robert Mittendorff wrote:
Using Delphi XE8 PE FireMonkey (on Windows 7)

I have several TEdit components on my form.

How can I programmatically change focus to the next edit component?

FMX seems not to have a SelectNext method like VCL does.

I created a Class Helper for FireMonkey TControl class to make navigation between the controls using the TabOrder:

unit MyTabOrderClassHelper;
 
interfaces
 
uses 
  System, FMX.Types, FMX.Controls;
 
type
   TFMXControlClassHelper = class helper for TControl
    public
      procedure SelectNext(CurControl: TControl; GoFoward: Boolean);
    end;
 
implementation
 
procedure TFMXControlClassHelper.SelectNext(CurControl: TControl; GoFoward: Boolean);
  var
    tablist          : ITabList;
    next             : IControl;
    parente, controle: TControl;
  begin
    controle := CurControl;
    parente  := controle.ParentControl;
    repeat
      tablist := parente.GetTabList;
      next    := tablist.FindNextTabStop(controle, GoFoward, True);
      if (not Assigned(next)) or (TControl(next) = controle) then
      begin
        controle := parente;
        parente  := parente.ParentControl;
      end
      else
        Break;
    until parente = nil;
 
    if (Assigned(next)) then
      controle := TControl(next)
    else
      controle := nil;
 
    if (Assigned(controle)) then
      controle.SetFocus;
  end;
 
 
end.


To use the helper Include the unit MyTabOrderClassHelper in the USES clause in the INTERFACE section.

Basic example of use:

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState);
begin
  case Key of
    vkEnter:
      TControl(Self).SelectNext(Self.GetActiveControl, True);
    vkTab:
      TControl(Self).SelectNext(Self.GetActiveControl, (not (ssShift in Shift)));
  end;
end;


Successfully tested in XE7 and later. Not tested in previous versions, who succeeds in previous versions please inform here to common knowledge.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02