TabSheetPageControl (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example requires a new TPageControl, with no new pages created at design time. The form OnCreate event handler adds several new TabSheet controls to the Page Control. The Page Control's OnChange event handler displays a message dialog when you change tabs. The message dialog contains the captions for the tabs immediately before and after the active tab.

Code

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  for i := 0 to 9 do
    with TTabSheet.Create(Self) do
    begin
      PageControl := PageControl1;
      Caption := 'TabSheet #' + IntToStr(i);
    end;
end;

procedure TForm1.PageControl1Change(Sender: TObject);
var
  PrevCaption, NextCaption: ShortString;
begin
  with (Sender as TPageControl) do
  begin
    PrevCaption :=
      FindNextPage(ActivePage, False, False).Caption;
    NextCaption :=
      FindNextPage(ActivePage, True, False).Caption;
  end;
  ShowMessage('Previous tab caption: "' + PrevCaption +
    '"    Next tab Caption: "' + NextCaption + '"');
end;

Uses