YOUSEFUL / DELPHI / SAMPLE PROJECTS
Wizard flow
A VCL program with a three-page TAtlasWizard built in code:
- Page 1 (Project) asks for a project name.
OnValidatevetoes Next while the name is empty and says why in the status line above the wizard. - Page 2 (Options) has a check box.
- Page 3 (Summary) shows the answers, refreshed by
OnPageChanged, and a Restart button that callsRestart. OnFinishreports the result once; after that Back and Next stay disabled until Restart.OnCancelcloses the window.
Build and run
Open WizardFlow.dpr in Delphi 13; the IDE creates the project file. Add the Atlas VCL src folder and the shared folder to the project's search path, then build and run for Win32 or Win64. No packages need to be installed. The shared folder is part of the sample download. It holds Atlas.TestVcl.pas, which the optional snapshot mode uses to save a picture of the window.
The program is interactive. WizardFlow.exe wizard.png paints the first page off screen, saves it as a PNG and exits.
Expected output
A 640 × 460 window with "Page 1 of 3" at the top, the prompt and an empty edit box, and the footer buttons Back (disabled), Next and Cancel.
- Press Next with the box empty: nothing moves and the status reads "Enter a project name before continuing."
- Type a name and press Next: "Page 2 of 3". Back returns to page 1 without validation.
- On page 3 the button reads Finish and the summary says, for example,
Create "Atlas" without a notification.Press Finish: the status starts with "Finished:" and Back and Next are disabled. - Press Restart: page 1 again, with the name still filled in.
- Cancel closes the window at any point.
What to change first
- Add a page by calling
AddPageand parenting your controls to the returnedTTabSheet; the Next button reads Finish on whichever page is last. - Put your own checks in
Validate, keyed byPageIndex. Show your own message: the wizard only stays on the page. - Do the real work in
Finished, for example setModalResult := mrOkwhen the form is shown withShowModal.
Project files
- WizardFlow.dpr
- README.md
- shared/Atlas.TestVcl.pas snapshot helper, in the download
The ZIP contains every sample project with its README. See getting started for the search path to add.
Source
WizardFlow.dpr
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.