diff --git a/lcl/include/customnotebook.inc b/lcl/include/customnotebook.inc index c055113dd2..b8cc315399 100644 --- a/lcl/include/customnotebook.inc +++ b/lcl/include/customnotebook.inc @@ -552,9 +552,9 @@ end; ------------------------------------------------------------------------------} procedure TCustomTabControl.SetPageIndex(AValue: Integer); begin + if (AValue < -1) or (AValue >= PageCount) then Exit; if (csLoading in ComponentState) then FLoadedPageIndex := AValue; //debugln('TCustomTabControl.SetPageIndex A ',dbgsName(Self),' AValue=',dbgs(AValue),' fPageIndex=',dbgs(fPageIndex),' PageCount=',dbgs(PageCount),' HandleAllocated=',dbgs(HandleAllocated),' ',dbgs(ComponentState)); - if (AValue < -1) or (AValue >= PageCount) then Exit; if FPageIndex = AValue then exit; if not CanChangePageIndex then exit; //debugln('TCustomTabControl.SetPageIndex B ',dbgsName(Self),' AValue=',dbgs(AValue),' fPageIndex=',dbgs(fPageIndex),' PageCount=',dbgs(PageCount),' HandleAllocated=',dbgs(HandleAllocated)); @@ -937,8 +937,8 @@ end; procedure TCustomTabControl.Loaded; begin inherited Loaded; - if FLoadedPageIndex >= -1 then - PageIndex := FLoadedPageIndex; + if FLoadedPageIndex > -1 then + PageIndex := FindVisiblePage(FLoadedPageIndex); FLoadedPageIndex := -1; //DebugLn(['TCustomTabControl.Loaded ',DbgSName(Self),' fPageIndex=',fPageIndex]); FPageIndexOnLastChange := PageIndex;