TCustomTabControl: only call MaybeSelectFirstControlOnPage if APage is not nil. Remove duplicate checks.

This commit is contained in:
Bart 2024-03-11 18:33:08 +01:00
parent 9fe0319df7
commit db41ce26cf

View File

@ -774,9 +774,10 @@ var
ParentForm: TCustomForm; ParentForm: TCustomForm;
C, ActiveControl: TWinControl; C, ActiveControl: TWinControl;
begin begin
Assert(Assigned(APage),'TCustomTabControl.MaybeSelectFirstControlOnPage: APage=nil');
ParentForm := GetParentForm(Self); ParentForm := GetParentForm(Self);
//Debugln(['TCustomTabControl.ActivateFirstControl: Self=',DbgSName(Self),', APage=',DbgSName(APage),', ParentForm=',DbgSName(ParentForm)]); //Debugln(['TCustomTabControl.ActivateFirstControl: Self=',DbgSName(Self),', APage=',DbgSName(APage),', ParentForm=',DbgSName(ParentForm)]);
if not (Assigned(APage) and Assigned(ParentForm) and APage.Visible and APage.Enabled and (APage.ControlCount > 0)) then if not (Assigned(ParentForm) and APage.Visible and APage.Enabled and (APage.ControlCount > 0)) then
Exit; Exit;
//Debugln(['TCustomTabControl.ActivateFirstControl: APage.Visible=',APage.Visible,', APage.Enabled=',APage.Enabled,', (APage.ControlCount > 0)=', (APage.ControlCount > 0)]); //Debugln(['TCustomTabControl.ActivateFirstControl: APage.Visible=',APage.Visible,', APage.Enabled=',APage.Enabled,', (APage.ControlCount > 0)=', (APage.ControlCount > 0)]);
ActiveControl := ParentForm.ActiveControl; ActiveControl := ParentForm.ActiveControl;
@ -1050,8 +1051,6 @@ end;
procedure TCustomTabControl.Change; procedure TCustomTabControl.Change;
var var
APage: TCustomPage; APage: TCustomPage;
ParentForm: TCustomForm;
ActiveControl: TWinControl;
begin begin
//DebugLn(['TCustomTabControl.Change ',DbgSName(Self),' fPageIndex=',fPageIndex]); //DebugLn(['TCustomTabControl.Change ',DbgSName(Self),' fPageIndex=',fPageIndex]);
ShowCurrentPage; ShowCurrentPage;
@ -1061,9 +1060,7 @@ begin
begin begin
APage := ActivePageComponent; APage := ActivePageComponent;
//debugln(['TCustomTabControl.Change: Self=',DbgSName(Self),', APage',DbgSName(APage)]); //debugln(['TCustomTabControl.Change: Self=',DbgSName(Self),', APage',DbgSName(APage)]);
//if Assigned(APage) then debugln(['APage.Visible=',APage.Visible,', APage.Enabled=',APage.Enabled,', (APage.ControlCount > 0)=',(APage.ControlCount > 0)]); if Assigned(APage) then
ParentForm := GetParentForm(Self);
if (Assigned(ParentForm) and Assigned(APage) and APage.Visible and APage.Enabled and (APage.ControlCount > 0)) then
MaybeSelectFirstControlOnPage(APage); MaybeSelectFirstControlOnPage(APage);
DoChange; DoChange;
@ -1099,11 +1096,15 @@ begin
end; end;
procedure TCustomTabControl.InternalSetPageIndex(AValue: Integer); procedure TCustomTabControl.InternalSetPageIndex(AValue: Integer);
var
APage: TCustomPage;
begin begin
FPageIndex := AValue; FPageIndex := AValue;
UpdateAllDesignerFlags; UpdateAllDesignerFlags;
DoSendPageIndex; DoSendPageIndex;
MaybeSelectFirstControlOnPage(GetActivePageComponent); APage := GetActivePageComponent;
if Assigned(APage) then
MaybeSelectFirstControlOnPage(APage);
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------