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 Reports— Generate a PDF Report Using a Headless (non-GUI) application
7+ # DevExpress VCL Reports — Generate 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
3029An application needs a template report layout, created in the [ Report Designer] ( https://docs.devexpress.com/VCL/405469/ExpressReports/vcl-reports ) .
31-
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- ###
30+ You can [ import a report layout from a REPX file] ( https://github.com/DevExpress-Examples/vcl-reports-store-layout-template-file )
31+ or [ read a layout from a database] ( https://github.com/DevExpress-Examples/vcl-reports-store-layout-template-database ) .
32+
33+ The current example imports a report layout from the ` Order.repx ` file.
34+
35+ ** Delphi:**
36+ ``` pas
37+ // Step 1: Create a report instance and load the report layout
38+ AReport := TdxReport.Create(nil); // AReport: TdxReport;
39+ try
40+ // Set an internal report name (does not affect the exported PDF content and file name)
41+ AReport.ReportName := 'OrderReport';
42+ // Load the report layout from the specified file
43+ AReport.Layout.LoadFromFile('..\Order.repx');
44+ // ...
45+ finally
46+ AReport.Free;
47+ end;
48+ ```
49+
50+ ### Step 2: Create a Database Connection
51+
52+ A VCL Report requires a source of data, which is usually represented by a database connection.
53+ The current example is using SQLite with the Northwind example database stored in ` nwind.db ` .
54+
55+ ``` pas
56+ // Step 2: Create a database connection
57+ // AConnection: TdxBackendDatabaseSQLConnection;
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+ // AReportParameter: TdxReportParameter;
84+ for AReportParameter in AReport.Parameters do
85+ if AReportParameter.Name = 'OrderIdParameter' then
86+ AReportParameter.Value := '11077';
87+ ```
88+
89+ 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 ) .
90+
91+ ### Step 4: Export and Save to a File
92+
93+ Once you have configured a report and a data source, and defined report parameters.
94+ you can export a report to one or more formats.
95+
96+ The current example exports a PDF report and saves it to a file:
97+
98+ ** Delphi:**
99+ ``` pas
100+ // Step 4: Export a report to PDF
101+ AStream := TMemoryStream.Create; // AStream: TMemoryStream;
102+ try
103+ // Export a report to PDF format and save it to a memory stream
104+ AReport.ExportToPDF(AStream);
105+ // Write the content of the memory stream to a file
106+ AStream.SaveToFile('Order_11077.pdf');
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