case Bureau.ActivePageIndex of 0 : Edit1.SetFocus; 1 : Edit2.SetFocus; 2 : Edit3.SetFocus; else begin TChild(Ft).StartFocus; // ft is a TForm (actually TChild Memo1.Lines.Add('StartFocus'); end; end;
{adding a TForm class TChild like this
procedure TMain.AddPageClick(Sender: TObject); var F : TChild; ATabItem : TTMSFMXPageControlPage; begin if Assigned(ft) then exit; F:=TChild.Create(Self); Ft:=F; ATabItem:=Bureau.AddPage(Format('Tab %d',[Bureau.Pages.Count])); ATabItem.TabSet.CanFocus:=False; ATabItem.TabSet.AllowFocus:=False; ATabItem.Container.AddObject(F.Layout1); end;
}
But without success, I check also that tabsets canfocus and allowfocus properties are false
To be noted the quasi same code works with TTabControl
Found a way, I use the OnAfterDrawTabBackground event to change the focus
procedure TMain.BureauPageAfterDrawTabBackground(Sender: TObject; AGraphics: TTMSFMXGraphics; ATabIndex: Integer; ARect: TRectF; AState: TTMSFMXTabSetTabState); begin if (ATabIndex= BureauPage.ActivePageIndex) then begin BureauPageChangeIndex(ATabIndex); end; end;
procedure TMain.BureauPageChangeIndex(index: integer); begin case Index of -1 : ; 0 : Edit1.SetFocus; 1 : Edit2.SetFocus; 2 : Edit3.SetFocus; else begin TChild(FP).StartFocus; DebugMemo.Lines.Add('StartFocus'); end; end; end;
But IMHO it's an unatural way do do the trick !
Is this not focusing control a bug or not ? that is the question
We're still investigating. It's unclear exactly what happens. Alternatively, you could set a FFocusedControl private variable and start a timer instead, which then focusses the control. Or set the TabStop property to False on each page.
It's less unnatural then using OnAfterDrawTabBackground. It could potentially be an FMX bug. We have used timers before for focusing controls in other applications, or event components such as inplace editors in the treeview, simply to workaround the issue.
Sorry I don't adhere this FMX bug theory, except if by this you speak about style.
Why ?
1- using the supplied ttabcontrol no problem to focus the wanted control
2- using OnAfterDrawTabBackground works great yes but i had to add some trick because with the code supplied i was enable to focus on a next control (ie a second Tedit). It is as if changing the focus of TEdit1 to TEdit2 (on the same page) fire the event !