program WizardFlow; // A three-page TAtlasWizard: the first page vetoes Next until a name is // entered, the last page summarises the answers, Finish fires once and // Restart begins again. Pass a file name to save a PNG of the window instead // of running it interactively. uses System.SysUtils, System.Classes, Vcl.Forms, Vcl.Controls, Vcl.StdCtrls, Vcl.ComCtrls, Atlas.Wizard, Atlas.TestVcl; type TWizardForm = class(TForm) private FWizard: TAtlasWizard; FName: TEdit; FNotify: TCheckBox; FSummary, FStatus: TLabel; function AddLabel(Page: TTabSheet; const Text: string; Top: Integer): TLabel; procedure Validate(Sender: TObject; PageIndex: Integer; var AllowNext: Boolean); procedure PageChanged(Sender: TObject); procedure Finished(Sender: TObject); procedure Cancelled(Sender: TObject); procedure RestartClicked(Sender: TObject); public constructor Create(AOwner: TComponent); override; end; constructor TWizardForm.Create(AOwner: TComponent); var Page: TTabSheet; Restart: TButton; begin inherited CreateNew(AOwner); Caption := 'Atlas VCL wizard'; Position := poScreenCenter; Width := 640; Height := 460; Font.Name := 'Segoe UI'; Font.Size := 10; FStatus := TLabel.Create(Self); FStatus.Parent := Self; FStatus.Align := alTop; FStatus.AlignWithMargins := True; FWizard := TAtlasWizard.Create(Self); FWizard.Parent := Self; FWizard.Align := alClient; FWizard.OnValidate := Validate; FWizard.OnPageChanged := PageChanged; FWizard.OnFinish := Finished; FWizard.OnCancel := Cancelled; Page := FWizard.AddPage('Project'); AddLabel(Page, 'Step 1 of 3: name the project. Next stays here until a name is entered.', 24); FName := TEdit.Create(Self); FName.Parent := Page; FName.SetBounds(24, 56, 320, 26); FName.TextHint := 'Project name'; Page := FWizard.AddPage('Options'); AddLabel(Page, 'Step 2 of 3: choose the options.', 24); FNotify := TCheckBox.Create(Self); FNotify.Parent := Page; FNotify.SetBounds(24, 56, 400, 24); FNotify.Caption := 'Send a notification when the project is created'; Page := FWizard.AddPage('Summary'); AddLabel(Page, 'Step 3 of 3: review the answers, then press Finish.', 24); FSummary := AddLabel(Page, '', 56); Restart := TButton.Create(Self); Restart.Parent := Page; Restart.SetBounds(24, 96, 120, 30); Restart.Caption := 'Restart'; Restart.OnClick := RestartClicked; PageChanged(FWizard); end; function TWizardForm.AddLabel(Page: TTabSheet; const Text: string; Top: Integer): TLabel; begin Result := TLabel.Create(Self); Result.Parent := Page; Result.SetBounds(24, Top, 560, 24); Result.Caption := Text; end; procedure TWizardForm.Validate(Sender: TObject; PageIndex: Integer; var AllowNext: Boolean); begin AllowNext := (PageIndex <> 0) or (Trim(FName.Text) <> ''); if not AllowNext then FStatus.Caption := 'Enter a project name before continuing.'; end; procedure TWizardForm.PageChanged(Sender: TObject); begin FStatus.Caption := Format('Page %d of %d', [FWizard.PageIndex + 1, FWizard.PageCount]); if FNotify.Checked then FSummary.Caption := Format('Create "%s" and send a notification.', [Trim(FName.Text)]) else FSummary.Caption := Format('Create "%s" without a notification.', [Trim(FName.Text)]); end; procedure TWizardForm.Finished(Sender: TObject); begin FStatus.Caption := 'Finished: ' + FSummary.Caption + ' Next and Back stay disabled until Restart.'; end; procedure TWizardForm.Cancelled(Sender: TObject); begin Close; end; procedure TWizardForm.RestartClicked(Sender: TObject); begin FWizard.Restart; end; var Form: TWizardForm; begin Application.Initialize; Application.MainFormOnTaskbar := True; Application.CreateForm(TWizardForm, Form); if ParamCount > 0 then SaveFormImage(Form, ParamStr(1)) else Application.Run; end.