YOUSEFUL / DELPHI / COMPONENTS

TAtlasWizard

Page-by-page wizard with Back, Next/Finish and Cancel buttons, a validation veto and finish, cancel and page-change events.

Visual control Palette: Atlas Unit Atlas.Wizard · Inherits TCustomPanel · Product Atlas VCL

Description

TAtlasWizard is a panel holding a page control with hidden tabs and a footer with Back, Next and Cancel buttons. AddPage returns an empty TTabSheet; parent your own controls to it. Next first calls OnValidate and moves on only if the handler leaves AllowNext True. On the last page the button reads Finish; accepting it sets Finished and fires OnFinish once, after which Back and Next are disabled until Restart or another AddPage. Back never validates. Cancel only fires OnCancel: closing the form or resetting the pages is up to you.

The page captions are stored on the tab sheets but not displayed. The button captions (Back, Next, Finish, Cancel) are fixed English text and the buttons are not exposed, so they cannot be restyled or translated through the API. Not implemented: removing pages, skipping or branching, a page header or progress indicator, and keyboard accelerators.

Members

MemberKindWhat it does
CreateconstructorCreates a 640 x 420 panel without bevel, a 54-pixel footer with the Back, Next and Cancel buttons, and no pages.
AddPagemethodAppends a page and returns its tab sheet, owned by the wizard.
NextmethodDoes what the Next button does.
BackmethodMoves to the previous page and fires OnPageChanged.
CancelmethodFires OnCancel, as the Cancel button does.
RestartmethodClears Finished, returns to the first page and fires OnPageChanged, also when the first page was already showing.
PageIndexpropertyZero-based current page; -1 when there are no pages.
PageCountpropertyNumber of pages.
FinishedpropertyTrue after Finish, until Restart or AddPage.
AlignpropertyStandard VCL alignment in the parent; usually alClient.
AnchorspropertyStandard VCL anchors.
ColorpropertyBackground of the panel.
FontpropertyFont of the wizard; the buttons and your page controls inherit it unless they set their own.
ParentFontpropertyStandard VCL property: use the parent's font.
OnValidateeventCalled by Next (button or method), also on the last page before Finish, with the current PageIndex and AllowNext set to True.
OnFinisheventFired once when Next is accepted on the last page.
OnCanceleventFired by the Cancel button and by Cancel.
OnPageChangedeventFired after Next, Back or Restart; Restart fires it even when the page does not change.

Constructors

Create constructor

constructor Create(AOwner: TComponent); override;

Creates a 640 x 420 panel without bevel, a 54-pixel footer with the Back, Next and Cancel buttons, and no pages.

Properties

PageIndex property

property PageIndex: Integer read GetPageIndex;

Zero-based current page; -1 when there are no pages.

PageCount property

property PageCount: Integer read GetPageCount;

Number of pages.

Finished property

property Finished: Boolean read FFinished;

True after Finish, until Restart or AddPage.

Align property

property Align;

Standard VCL alignment in the parent; usually alClient.

Anchors property

property Anchors;

Standard VCL anchors.

Color property

property Color;

Background of the panel.

Font property

property Font;

Font of the wizard; the buttons and your page controls inherit it unless they set their own.

ParentFont property

property ParentFont;

Standard VCL property: use the parent's font.

Events

OnValidate event

property OnValidate: TAtlasPageValidationEvent read FOnValidate write FOnValidate;

Called by Next (button or method), also on the last page before Finish, with the current PageIndex and AllowNext set to True. Set AllowNext to False to stay on the page; show your own message, the wizard shows none.

OnFinish event

property OnFinish: TNotifyEvent read FOnFinish write FOnFinish;

Fired once when Next is accepted on the last page.

OnCancel event

property OnCancel: TNotifyEvent read FOnCancel write FOnCancel;

Fired by the Cancel button and by Cancel.

OnPageChanged event

property OnPageChanged: TNotifyEvent read FOnPageChanged write FOnPageChanged;

Fired after Next, Back or Restart; Restart fires it even when the page does not change. Not fired by AddPage or on Finish.

Methods

AddPage method

function AddPage(const Caption: string): TTabSheet;

Appends a page and returns its tab sheet, owned by the wizard. The first page added becomes the current page; later ones do not change it. Clears Finished and updates the buttons.

pascal
Page := Wizard.AddPage('Account');
Edit := TEdit.Create(Wizard);
Edit.Parent := Page;

Next method

function Next: Boolean;

Does what the Next button does. Returns False without doing anything when there are no pages or the wizard is finished, and False when OnValidate vetoes. Otherwise moves to the next page and fires OnPageChanged, or on the last page sets Finished and fires OnFinish, and returns True.

pascal
while Wizard.Next and not Wizard.Finished do ;

Back method

function Back: Boolean;

Moves to the previous page and fires OnPageChanged. Returns False on the first page or when finished. Does not call OnValidate.

Cancel method

procedure Cancel;

Fires OnCancel, as the Cancel button does. Changes nothing else.

Restart method

procedure Restart;

Clears Finished, returns to the first page and fires OnPageChanged, also when the first page was already showing. The controls on the pages keep their contents.

Examples

Two-page wizard in a dialog

The first page requires a name; Finish and Cancel close the dialog with a modal result. Show it with ShowModal.

pascal
uses System.SysUtils, System.Classes, Vcl.Forms, Vcl.Controls, Vcl.StdCtrls, Vcl.ComCtrls, Atlas.Wizard;

type
  TSetupWizard = class(TForm)
  private
    FWizard: TAtlasWizard;
    FName: TEdit;
    procedure Validate(Sender: TObject; PageIndex: Integer; var AllowNext: Boolean);
    procedure Finished(Sender: TObject);
    procedure Cancelled(Sender: TObject);
  public
    constructor Create(AOwner: TComponent); override;
  end;

constructor TSetupWizard.Create(AOwner: TComponent);
var
  Page: TTabSheet;
  Prompt: TLabel;
begin
  inherited CreateNew(AOwner);
  Caption := 'New project';
  FWizard := TAtlasWizard.Create(Self);
  FWizard.Parent := Self;
  FWizard.Align := alClient;
  FWizard.OnValidate := Validate;
  FWizard.OnFinish := Finished;
  FWizard.OnCancel := Cancelled;
  Page := FWizard.AddPage('Name');
  FName := TEdit.Create(Self);
  FName.Parent := Page;
  FName.SetBounds(24, 24, 300, 26);
  Page := FWizard.AddPage('Confirm');
  Prompt := TLabel.Create(Self);
  Prompt.Parent := Page;
  Prompt.SetBounds(24, 24, 400, 24);
  Prompt.Caption := 'Press Finish to create the project.';
end;

procedure TSetupWizard.Validate(Sender: TObject; PageIndex: Integer; var AllowNext: Boolean);
begin
  if PageIndex = 0 then AllowNext := Trim(FName.Text) <> '';
end;

procedure TSetupWizard.Finished(Sender: TObject);
begin
  ModalResult := mrOk;
end;

procedure TSetupWizard.Cancelled(Sender: TObject);
begin
  ModalResult := mrCancel;
end;

Drive the wizard from code

Presses Next until the wizard finishes or a page vetoes, for example in a test.

pascal
uses Atlas.Wizard;

function RunThrough(Wizard: TAtlasWizard): Boolean;
begin
  Wizard.Restart;
  while Wizard.Next and not Wizard.Finished do ;
  Result := Wizard.Finished;
end;

TAtlasPageValidationEvent

Also in Atlas VCL

TAtlasTable · TAtlasGrid · TAtlasValueEdit · TAtlasTree · TAtlasWorkbook · TAtlasSheetGrid · TAtlasPivot · TAtlasInspector · TAtlasRichEdit · TAtlasSpellChecker · TAtlasChart · TAtlasGauge · TAtlasThemer · TAtlasWorkspace · TAtlasCommandBar · TAtlasActionTile · TAtlasTileBoard · TAtlasNavigation · TAtlasMap · TAtlasGraph · TAtlasDiagram · TAtlasPrintDocument · TAtlasSchedule · TAtlasScheduler · TAtlasTaskPlan · TAtlasGantt · TAtlasPdfDocument · TAtlasPdfViewer