TTabControl
English · Français · Русский · 中文(中国)
TTabControl
is a descendant of TWinControl and can be found on the Common Controls tab of the Component Palette.
It is a tabbed container component which looks identical to a TPageControl. However, there is a fundamental difference because the control always shows the same page whichever tab is selected. In fact, it containts only a single page. The idea behind this concept is illustrated best by an editor or viewer for text files: When the TabControl contains a TMemo then the individual tabs refer to the files loaded into the memo; whenever the active tab changes another file is loaded into the (same) memo.
Since the TTabControl contains only a single page there is no Pages property as for the TPageControl. The individual tab captions are stored in a TStrings property named Tabs.
The currently selected tab can be identified by means of its index, TabIndex.
Navigating between tabs
The user can navigate between tabs by clicking on the tab to be used. By code, the same can be achieved by assigning the index of the new tab to the TabIndex property of the TTabControl.
Whenever another tab is displayed two events are fired:
OnChangeis called after the new tab has become active. In the file editor example, the new file contents must be loaded into the memo shown on theTTabControl.OnChangingis called before the new tab will becomes active. In the file editor example, the contents loaded into the memo must be stored away before it will be replaced by the data for the new tab. Moreover, this event has a parameterAllowChangewhich can be set tofalseto prevent the tab change, for example because the data shown for the previously selected tab have been edited and contain some error to be fixed.
Adding tabs
- At designtime, right-click on the
TTabControland select the option Add page from the context menu. - At runtime, add a new string to the
Tabsproperty:
procedure TForm1.AddTabBtnClick(Sender: TObject);
begin
TabControl1.Tabs.Add('abc');
end;Deleting tabs
- At designtime, right-click on the
TTabControland select the option Delete tab from the context menu. - At runtime, delete the item with the specific index from the
Tabslist.
procedure TForm1.DeleteTabBtn(Sender: TObject);
begin
if TabControl1.TabIndex > -1 then
TabControl1.Tabs.Delete(TabControl1.tabIndex);
end;Similar controls
See also
From the Free Pascal wiki, page "TTabControl", as it stood on 2021-02-06 after a change by Wp, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.
