Skip to content

Commit 1cf7b7e

Browse files
delphi: update project code (fixup before merging)
Co-authored-by: Nick Volynkin <nikolay.volynkin@devexpress.com> Co-authored-by: Ilia Nenashev <ilia.nenashev@devexpress.com>
1 parent f77ff36 commit 1cf7b7e

1 file changed

Lines changed: 48 additions & 47 deletions

File tree

Delphi/PDFReportGenerator.dpr

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,79 +8,80 @@ uses
88
System.SysUtils,
99
System.Classes,
1010
System.IniFiles,
11-
dxBackend,
11+
dxBackend, // DevExpress Reports and Dashboards backend
1212
dxBackend.Bundled,
1313
dxBackend.ConnectionString.SQL,
14-
dxReport;
14+
dxReport, // DevExpress Reports frontend
15+
dxReport.Parameters;
1516

1617
procedure ExportReportToPdf;
1718
var
18-
AManager: TdxBackendDataConnectionManager;
19+
AConfig: TIniFile;
1920
AConnection: TdxBackendDatabaseSQLConnection;
2021
AReport: TdxReport;
21-
22+
AReportParameter: TdxReportParameter;
2223
AStream: TMemoryStream;
23-
24-
AIni: TIniFile;
25-
26-
AParamName: string;
27-
AKeys: TStringList;
28-
I: Integer;
2924
begin
30-
TdxBackend.Instance.Start; // Start the backend
25+
// Start the DevExpress backend.
26+
TdxBackend.Instance.Start;
3127

32-
AManager := TdxBackendDataConnectionManager.Create(nil);
33-
AIni := TIniFile.Create('..\PDFReportGenerator.ini');
28+
// Read the configuration file.
29+
AConfig := TIniFile.Create('..\PDFReportGenerator.ini');
3430
try
35-
AConnection := TdxBackendDatabaseSQLConnection(AManager.DataConnections.
36-
Add(TdxBackendDatabaseSQLConnection));
37-
38-
AConnection.DisplayName := AIni.ReadString('Connection', 'Name', '');
39-
AConnection.ConnectionString :=
40-
AIni.ReadString('Connection', 'ConnectionString', '');
41-
AConnection.Active := True;
42-
43-
AReport := TdxReport.Create(nil);
31+
// Create a database connection.
32+
AConnection := TdxBackendDatabaseSQLConnection.Create(nil);
4433
try
45-
AReport.Layout.LoadFromFile(AIni.ReadString('Report', 'LayoutFileName', ''));
46-
AReport.ReportName := 'Report';
47-
48-
AReport.LoadParametersFromReport;
34+
// Assign the name "MS SQL Connection" to the database connection.
35+
// As part of this operation, the connection manager registers the connection and makes it available to reports.
36+
AConnection.DisplayName := AConfig.ReadString('Connection', 'Name', '');
37+
// Assign the specified connection string to the database connection.
38+
AConnection.ConnectionString := AConfig.ReadString('Connection', 'ConnectionString', '');
4939

50-
AKeys := TStringList.Create;
40+
// Create a new DevExpress Report.
41+
AReport := TdxReport.Create(nil);
5142
try
52-
for I := 0 to AKeys.Count - 1 do
53-
begin
54-
AParamName := AKeys[I];
43+
// Assign a name to the newly created report.
44+
AReport.ReportName := 'Report';
45+
// Load report layout from a `.repx` layout file.
46+
// Report layout contains visual elements and data bindings:
47+
// - List of parameters used to filter data obtained from a database and displayed in the report.
48+
// - Database connection name and SQL query to obtain data from a database.
49+
AReport.Layout.LoadFromFile(AConfig.ReadString('Report', 'LayoutFileName', ''));
50+
51+
// Read a list of parameter names from the layout file.
52+
// (Presented layout file has a single parameter named `CategoryNameReportParameter`.)
53+
AReport.LoadParametersFromReport;
5554

56-
if AReport.Parameters.ParamByName[AParamName] <> nil then
57-
AReport.Parameters
58-
.ParamByName[AKeys[I]]
59-
.Value := AIni.ReadString('Parameters', AParamName, '');
60-
end;
61-
finally
62-
AKeys.Free;
63-
end;
55+
// For each parameter, read and assign its value from the configuration file.
56+
// Parameter values are used to filter data obtained from a database.
57+
// The presented technique allows you to produce various reports by filtering data with parameters.
58+
for AReportParameter in AReport.Parameters do
59+
AReportParameter.Value := AConfig.ReadString('Parameters', AReportParameter.Name, '');
6460

65-
AStream := TMemoryStream.Create;
66-
try
67-
AReport.ExportToPDF(AStream);
68-
AStream.SaveToFile(AIni.ReadString('Report', 'OutputFileName', ''))
61+
// Create a memory stream to hold the exported PDF data.
62+
AStream := TMemoryStream.Create;
63+
try
64+
// Export the report to PDF format and save it to the memory stream.
65+
AReport.ExportToPDF(AStream);
66+
// Write the content of the memory stream to an output file.
67+
// The file name is specified in the configuration file.
68+
AStream.SaveToFile(AConfig.ReadString('Report', 'OutputFileName', ''));
69+
finally
70+
AStream.Free;
71+
end;
6972
finally
70-
AStream.Free;
73+
AReport.Free;
7174
end;
7275
finally
73-
AReport.Free;
76+
AConnection.Free;
7477
end;
7578
finally
76-
AManager.Free;
77-
AIni.Free;
79+
AConfig.Free;
7880
end;
7981
end;
8082

8183
begin
8284
try
83-
{ TODO -oUser -cConsole Main : Insert code here }
8485
ExportReportToPdf;
8586
except
8687
on E: Exception do

0 commit comments

Comments
 (0)