Question
“How can I can create a simple report wizard that implements a standard template?”
Solution
The following example shows how to create a custom report wizard and register it with RB. The TmyReportWizard class descends from TppCustomReportWizard and overrides a few simple methods. The ClassDescription and ClassBitmpa are used by the report designer’s ‘New…’ dialog. The Execute method loads a report template, called base.rtm. The initialization/finalization is used to register/unregister the wizard.
Download: ReportTemplateWizard.zip
Sample Delphi code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
TmyReportWizard = class(TppCustomReportWizard) private FReport: TppCustomReport; FReportName: String; protected function GetReport: TObject; override; function GetReportName: String; override; public constructor Create(aOwner: TComponent); override; destructor Destroy; override; class function ClassDescription: String; override; class function ClassBitmap: THandle; override; function Execute: Boolean; override; end; {class, TmyReportWizard} implementation {$R myRptWiz.RES} {****************************************************************************** * ** R E P O R T W I Z A R D * {******************************************************************************} {------------------------------------------------------------------------------} { TmyReportWizard.Create } constructor TmyReportWizard.Create(aOwner: TComponent); begin inherited Create(aOwner); FReport := nil; FReportName := ''; end; {------------------------------------------------------------------------------} { TmyReportWizard.Destroy } destructor TmyReportWizard.Destroy; begin inherited Destroy; end; {------------------------------------------------------------------------------} { TmyReportWizard.ClassDescription } class function TmyReportWizard.ClassDescription: String; begin Result := 'My Default Template'; end; {------------------------------------------------------------------------------} { TmyReportWizard.ClassBitmap } class function TmyReportWizard.ClassBitmap: THandle; begin Result := ppBitmapFromResource('PPREPORTWIZARD'); end; {------------------------------------------------------------------------------} { TmyReportWizard.Execute } function TmyReportWizard.Execute: Boolean; begin Result := True; // get a reference to the report DoOnCreateReport(DataName, TObject(FReport)); if (FReport = nil) then Exit; // load the default report template FReport.Template.FileName := ExtractFilePath(ParamStr(0)) + 'base.rtm'; FReport.Template.LoadFromFile; end; {------------------------------------------------------------------------------} { TmyReportWizard.GetReport } function TmyReportWizard.GetReport: TObject; begin Result := FReport; end; {------------------------------------------------------------------------------} { TmyReportWizard.GetReportName } function TmyReportWizard.GetReportName: String; begin Result := FReportName; end; {****************************************************************************** * ** I N I T I A L I Z A T I O N / F I N A L I Z A T I O N * {******************************************************************************} initialization // replace default wizard used to create empty reports ppRegisterDefaultBlankReportWizard(TmyReportWizard); // replace the default dialog based wizard // ppRegisterDefaultReportWizard(TmyReportWizard); // add a new wizard // ppRegisterWizard(TmyReportWizard); finalization ppUnRegisterWizard(TmyReportWizard); end. |