'Report
Template' refers to the binary image
created when a report layout is saved to a file or
to a database BLOB field. You can use report
templates to free your report definitions from the
confines of the executable in which they are being
utilized. Therefore, if you need to make
modifications to a report, you can do so without
recompiling and redeploying your entire application.
Simply send the new report layout file or database
table containing the report layouts to your users.
If you save report layouts to files or database BLOB
fields, you can use them to create a versioning
system for reports. This way, the original reports
supplied with your application are never modified,
but end-users can create versions of these reports.
In order to allow end-users to modify the reports
via the Report Designer, ReportBuilder Professional
is required.
ReportBuilder report templates leverage technology
already present in Delphi. The same logic that is
used to save the state of objects as configured on a
Delphi form (and stored in a dfm file) is used to
save the components of a report layout (in an rtm
file). In order to view the content of an .rtm file,
set the Report.Template.Format to
ftASCII and save
the report. Then open the resulting rtm file in the
Delphi code editor. You will be able to see the
structure of this file format.
File-based Templates
You can load and save report layouts to files using
the Report Designer. You can also accomplish this
programmatically:
1. Using the Report Designer:
Set the Report.Template.SaveTo property to
stFile
(this is the default value). |
| |
A.
Saving a Report Layout
Select the File | Save As… menu option from within
the Report Designer. The standard Windows file save
dialog will be displayed, enabling you to save the
report template to a .rtm file. |
| |
B.
Loading a Report Template
Select the File | Open… menu option from within the
Report Designer. The standard Windows file open
dialog will be displayed, enabling you to select and
open a .rtm file. |
|
2. Programmatically
|
| |
A.
Saving a Report Layout
The following code saves a report in the
‘test.rtm’
file: |
ppReport1.Template.FileName :=
‘c:\test.rtm’;
ppReport1.Template.SaveToFile; |
| |
B.
Loading a Report Template
The following code opens a report layout and prints
the report: |
ppReport1.Template.FileName := ‘c:\test.rtm’;
ppReport1.Template.LoadFromFile; ppReport.Print; |
Database Templates
You can save and load data-based report templates by
using the Report Designer or programmatically.
Defining the Database Table
Report definitions can be stored to any database
table with the following structure:
| Database Table Structure |
|
Name |
Char(40) |
The name of the report is stored in this field. |
|
Template |
BLOB or Memo |
The report definition is stored in this field. If
the format is binary, the field should be a BLOB. If
the format is ASCII, the field should be a memo. |
Connecting the Report object to the database
Once the database table has been defined, the next
step is to connect the report to the database table.
This task is accomplished by configuring the
following properties of the Report.Template object.
You can do this via the Delphi Object Inspector or
programmatically.
Report.Template.DatabaseSettings.NameField :=
‘Name’;
Report.Template.DatabaseSettings.TemplateField :=
‘Template’;
Report.Template.DatabaseSettings.DataPipeline :=
plReports;
Loading and Saving Reports
|
1. Using the Report Designer:
Set the
Report.Template.SaveTo property to
stDatabase.
|
| |
A. Saving
a Report Layout
Select the File | Save As…
menu option from within the Report Designer. A
special Save dialog will be displayed, showing
all reports in the given database table. You can
name the report and then save it to the table.
|
| |
B. Loading a Report Template
Select the File | Save As… menu option from
within the Report Designer. Once a report is
saved, you can load it by accessing the File |
Open dialog. |
|
2.
Programmatically
|
| |
A. Saving a Report Layout
The following code saves a report in the
‘test.rtm’
file: |
ppReport1.Template.FileName :=
‘Order Summary’;
ppReport1.Template.SaveToDatabase; |
| |
B. Loading a Report Template
The following code opens a report layout and
prints the report: |
ppReport1.Template. DatabaseSettings.Name :=
‘Order Summary’;
ppReport1.Template.LoadFromDatabase;
ppReport.Print; |