Skip to content

Commit 4ac94f9

Browse files
committed
readme: Explain implementation steps
1 parent e89c668 commit 4ac94f9

1 file changed

Lines changed: 93 additions & 15 deletions

File tree

README.md

Lines changed: 93 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
[![](https://img.shields.io/badge/💬_Leave_Feedback-feecdd?style=flat-square)](#does-this-example-address-your-development-requirementsobjectives)
55
<!-- default badges end -->
66

7-
# DevExpress VCL ReportsGenerate a PDF Report Using a Headless (non-GUI) application
7+
# DevExpress VCL ReportsGenerate a Report Using a Headless (non-GUI) Application
88

9-
This example uses the DevExpress VCL Reports components to generate a PDF report using a command line application.
10-
The example demonstrates the capabilities of VCL Reports for producing reports in backend applications, webservers, or command line applications, all without the need for a GUI.
9+
This example uses the DevExpress VCL Reports to generate a PDF report using a command line application.
10+
The example demonstrates the capabilities of VCL Reports for producing reports in backend applications, Windows services,
11+
or plain command line applications, all without the need for a GUI.
1112

12-
The example includes projects for both [Delphi](./Delphi) and [C++Builder](./CPB).
13-
14-
> ![Example of a PDF report produced by the command line application, showing an alphabetical list of products](./images/report.png)
13+
> ![Example of a PDF report produced by the command line application, showing customer order number 11077](./images/report.png)
1514
1615
## Prerequisites
1716

@@ -22,19 +21,98 @@ See: [DevExpress Reports Prerequisites](https://docs.devexpress.com/VCL/405773/E
2221
2322
## Implementation Details
2423

25-
By following the steps outlined in this example, you'll create an application that produce the
26-
[DevExpress VCL Reports](https://docs.devexpress.com/VCL/405469/ExpressReports/vcl-reports).
24+
By following the steps outlined in this example, you'll create an application that imports a report layout from a file,
25+
connects it with a data source, and exports a ready report to a PDF file.
2726

28-
### Prepare a Template Report Layout
27+
### Step 1: Initialize a Report and Import a Report Layout
2928

3029
An application needs a template report layout, created in the [Report Designer](https://docs.devexpress.com/VCL/405469/ExpressReports/vcl-reports).
3130

32-
You can [store a report layout in a REPX file](https://github.com/DevExpress-Examples/vcl-reports-store-layout-template-file)
33-
or [in a database](https://github.com/DevExpress-Examples/vcl-reports-store-layout-template-database).
34-
35-
This example loads a report layout from the [`Order.repx`](./Order.repx) file.
36-
37-
###
31+
You can [import a report layout from a REPX file](https://github.com/DevExpress-Examples/vcl-reports-store-layout-template-file)
32+
or [read a layout from a database](https://github.com/DevExpress-Examples/vcl-reports-store-layout-template-database).
33+
34+
The current example imports a report layout from the `Order.repx` file.
35+
36+
**Delphi:**
37+
```pas
38+
// Step 1: Create a report instance and load the report layout
39+
AReport := TdxReport.Create(nil);
40+
try
41+
// Set an internal report name (does not affect the exported PDF content and file name)
42+
AReport.ReportName := 'OrderReport';
43+
// Load the report layout from the specified file
44+
AReport.Layout.LoadFromFile(ALayout);
45+
// ...
46+
finally
47+
AReport.Free;
48+
end;
49+
```
50+
51+
### Step 2: Create a Database Connection
52+
53+
A VCL Report requires a source of data, which is usually represented by a database connection.
54+
The current example is using SQLite with the Northwind example database stored in `nwind.db`.
55+
56+
```pas
57+
// Step 2: Create a database connection
58+
AConnection := TdxBackendDatabaseSQLConnection.Create(nil);
59+
try
60+
// Assign a database name matching the name specified in the report layout
61+
AConnection.DisplayName := 'NWindConnectionString';
62+
// Assign a connection string to use the local SQLite database
63+
AConnection.ConnectionString := 'XpoProvider=SQLite; Data Source=..\nwind.db; Mode=ReadOnly';
64+
// ...
65+
finally:
66+
AConnection.Free;
67+
end:
68+
```
69+
70+
### Step 3: Define Report Parameter Values
71+
72+
A report layout may have one or more parameters.
73+
VCL Reports use parameters to modify database queries and produce different reports using the same layout and data.
74+
For example, `Order.repx`has a single `OrderIDParameter` used to produce reports on customer orders with given Order IDs.
75+
76+
To modify parameters, load them using the `LoadParametersFromReport` method and assign values to members of the `Report.Parameters` list:
77+
78+
**Delphi:**
79+
```pas
80+
// Step 2: Define Report Parameter Values
81+
AReport.LoadParametersFromReport;
82+
// Set the value of the "OrderIdParameter" parameter in the report layout
83+
for AReportParameter in AReport.Parameters do
84+
if AReportParameter.Name = 'OrderIdParameter' then
85+
AReportParameter.Value := AOrderID;
86+
```
87+
88+
To learn more, follow the guide: [VCL Backend: Supported Database Systems](https://docs.devexpress.com/VCL/405703/ExpressCrossPlatformLibrary/vcl-backend/vcl-backend-supported-database-systems).
89+
90+
### Step 4: Export and Save to a File
91+
92+
Once you have configured a report and a data source, and defined report parameters.
93+
you can export a report to one or more formats.
94+
95+
The current example exports a PDF report and saves it to a file:
96+
97+
**Delphi:**
98+
```pas
99+
// Step 4: Export a report to PDF
100+
AStream := TMemoryStream.Create;
101+
try
102+
// Export a report to PDF format and save it to a memory stream
103+
AReport.ExportToPDF(AStream);
104+
// Write the content of the memory stream to a file
105+
AStream.SaveToFile(AOutput);
106+
Writeln('Report saved to: ', AOutput);
107+
finally
108+
AStream.Free;
109+
end;
110+
```
111+
112+
### Optional: Exporting Multiple Reports
113+
114+
Headless approach allows you to efficiently produce multiple reports using the same layout and data, but different parameter combinations.
115+
You can repeat steps 3 and 4 for each parameter combinations.
38116

39117

40118
## Files to Review

0 commit comments

Comments
 (0)