Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

Traversing through Tabs and Pages

  • 2 minutes to read

The TcxTabControl and TcxPageControl controls maintain collections of tabs and pages respectively. This topic describes the ways to traverse through these collections in order to access each page/tab.

First, let’s consider the way in which to visit each tab of the TcxTabControl control. Its tabs collection is represented by the Tabs property, which is of type TcxTabs. The Tabs property of this class provides indexed access to individual tabs. The Count property returns the total number of tabs in the collection. Consider the code example below:

Delphi
var
  CurrTab: TcxTab;
  i: Integer;
// ...
for i := 0 to cxTabControl1.Tabs.Count - 1 do
begin
  CurrTab := cxTabControl1.Tabs[i];
  // ...
end;

It must be noted here, that the following two lines of code are of identical effect:

Delphi
CurrTab := cxTabControl1.Tabs[i];
CurrTab := cxTabControl1.Tabs.Tabs[i];

Let’s now consider how to traverse through the pages of the TcxPageControl control. This involves using the Pages property to access individual pages by their indexes. The total number of pages is determined via the PageCount property. Consider the code below:

Delphi
var
  CurrPage: TcxTabSheet;
  i: Integer;
// ...
for i := 0 to cxPageControl1.PageCount - 1 do
begin
  CurrPage := cxPageControl1.Pages[i];
  // ...
end;

The TcxPageControl control provides you one more way to traverse through its pages. The FindNextPage method is used for this purpose. The following sample code iterates backward through every page in starting from the current page.

Delphi
var
  CurrPage: TcxTabSheet;
  StartIndex: Integer;
// ...
StartIndex := cxPageControl1.ActivePageIndex;
CurrPage := cxPageControl1.ActivePage;
repeat
  CurrPage := cxPageControl1.FindNextPage(CurrPage, False, False);
  // ...
until CurrPage.PageIndex = StartIndex;