Custom Wizards Writing
You can extend FastReport functionality with help of custom wizards. FastReport, for example, contains standard “Report Wizard,” which is called from “File|New…” menu.
There are two types of wizards supported in FastReport. The first type includes wizards already mentioned, called from “File|New…” menu. The second one includes wizards, which can be called from “Wizards” toolbar.
Basic class for any wizard is TfrxCustomWizard
, defined in “frxClass” file.
TfrxCustomWizard = class(TComponent)
Public
Constructor Create(AOwner: TComponent); override;
class function GetDescription: String; virtual; abstract;
function Execute: Boolean; virtual; abstract;
property Designer: TfrxCustomDesigner read FDesigner;
property Report: TfrxReport read FReport;
end;
To write your own wizard, it is necessary to inherit from this class and override at least GetDescription
and Execute
methods. The first one returns wizard name; the second one is called when running the wizard; it must return “True,” if wizard finished working successfully and made any changes to report. During wizard work, you can call designer and report methods and properties properly via Designer
and Report
properties.
Wizard registration and deleting is performed via procedures described in “frxDsgnIntf” file:
frxWizards.Register(ClassRef: TfrxWizardClass; ButtonBmp: TBitmap; IsToolbarWizard: Boolean = False);
frxWizards.Unregister(ClassRef: TfrxWizardClass);
At registration, one enters wizard class name, its picture, and specifies if wizard is placed in “Wizards” toolbar. If wizard should be placed in toolbar, ButtonBmp size must be either 16x16 pixels, or otherwise 32x32 pixels.
Let us examine primitive wizard, which is being registered in "File|New..." menu, and then adds new page to report.
uses frxClass, frxDsgnIntf;
type
TfrxMyWizard = class(TfrxCustomWizard)
public
class function GetDescription: String; override;
function Execute: Boolean; override;
end;
class function TfrxMyWizard.GetDescription: String;
begin
Result := 'My Wizard';
end;
function TfrxMyWizard.Execute: Boolean;
var
Page: TfrxReportPage;
begin
{ lock any drawings in designer }
Designer.Lock;
{ create new page in report }
Page := TfrxReportPage.Create(Report);
{ create unique name for page }
Page.CreateUniqueName;
{ set paper sizes and orientation by default }
Page.SetDefaults;
{ update report pages and switch focus to last added page }
Designer.ReloadPages(Report.PagesCount - 1);
end;
var
Bmp: TBitmap;
initialization
Bmp := TBitmap.Create;
{ load picture from resource; of course, you should place it there first }
Bmp.LoadFromResourceName(hInstance, 'frxMyWizard');
frxWizards.Register(TfrxMyWizard, Bmp);
finalization
frxWizards.Unregister(TfrxMyWizard);
Bmp.Free;
end.