Skip to content

Commit f77ff36

Browse files
delphi: Add application example
1 parent 5b43efc commit f77ff36

7 files changed

Lines changed: 1447 additions & 0 deletions

File tree

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
# Most of the time, files here have not there place in a code repository.
3232
#Win32/
3333
#Win64/
34+
#Win64x/
3435
#OSX64/
3536
#OSXARM64/
3637
#Android/
@@ -61,6 +62,7 @@
6162
*.cfg
6263
*.hpp
6364
*Resource.rc
65+
*.rsp
6466

6567
# Delphi local files (user-specific info)
6668
*.local
@@ -75,6 +77,39 @@ __history/
7577
__recovery/
7678
*.~*
7779

80+
81+
# ------------------------------------------------------------
82+
# C++Builder specific
83+
# ------------------------------------------------------------
84+
85+
# C++Builder compiler outputs
86+
*.obj
87+
*.hpp
88+
*.ilc
89+
*.ild
90+
*.ilf
91+
*.ils
92+
*.map
93+
*.tds
94+
95+
# Precompiled headers
96+
*.pch
97+
98+
# C++Builder packages and libraries
99+
*.bpl
100+
*.bpi
101+
*.lib
102+
*.a
103+
*.dll
104+
*.so
105+
106+
# C++Builder intermediate / cache files
107+
*.cbproj.local
108+
*.cbproj.identcache
109+
*.cbproj.user
110+
*.cbtemp
111+
112+
78113
# Castalia statistics file (since XE7 Castalia is distributed with Delphi)
79114
*.stat
80115

Delphi/PDFReportGenerator.dpr

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
program PDFReportGenerator;
2+
3+
{$APPTYPE CONSOLE}
4+
5+
{$R *.res}
6+
7+
uses
8+
System.SysUtils,
9+
System.Classes,
10+
System.IniFiles,
11+
dxBackend,
12+
dxBackend.Bundled,
13+
dxBackend.ConnectionString.SQL,
14+
dxReport;
15+
16+
procedure ExportReportToPdf;
17+
var
18+
AManager: TdxBackendDataConnectionManager;
19+
AConnection: TdxBackendDatabaseSQLConnection;
20+
AReport: TdxReport;
21+
22+
AStream: TMemoryStream;
23+
24+
AIni: TIniFile;
25+
26+
AParamName: string;
27+
AKeys: TStringList;
28+
I: Integer;
29+
begin
30+
TdxBackend.Instance.Start; // Start the backend
31+
32+
AManager := TdxBackendDataConnectionManager.Create(nil);
33+
AIni := TIniFile.Create('..\PDFReportGenerator.ini');
34+
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);
44+
try
45+
AReport.Layout.LoadFromFile(AIni.ReadString('Report', 'LayoutFileName', ''));
46+
AReport.ReportName := 'Report';
47+
48+
AReport.LoadParametersFromReport;
49+
50+
AKeys := TStringList.Create;
51+
try
52+
for I := 0 to AKeys.Count - 1 do
53+
begin
54+
AParamName := AKeys[I];
55+
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;
64+
65+
AStream := TMemoryStream.Create;
66+
try
67+
AReport.ExportToPDF(AStream);
68+
AStream.SaveToFile(AIni.ReadString('Report', 'OutputFileName', ''))
69+
finally
70+
AStream.Free;
71+
end;
72+
finally
73+
AReport.Free;
74+
end;
75+
finally
76+
AManager.Free;
77+
AIni.Free;
78+
end;
79+
end;
80+
81+
begin
82+
try
83+
{ TODO -oUser -cConsole Main : Insert code here }
84+
ExportReportToPdf;
85+
except
86+
on E: Exception do
87+
Writeln(E.ClassName, ': ', E.Message);
88+
end;
89+
end.

Delphi/PDFReportGenerator.dproj

Lines changed: 1131 additions & 0 deletions
Large diffs are not rendered by default.

Delphi/PDFReportGenerator.res

96 Bytes
Binary file not shown.

Delphi/Products.pdf

88.3 KB
Binary file not shown.

Layout.repx

Lines changed: 182 additions & 0 deletions
Large diffs are not rendered by default.

PDFReportGenerator.ini

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[Connection]
2+
Name=MS SQL Connection
3+
ConnectionString=XpoProvider=MSSqlServer;data source=localhost;initial catalog=Northwind;integrated security=SSPI;TrustServerCertificate=True;
4+
5+
[Report]
6+
LayoutFileName=..\Layout.repx
7+
OutputFileName=Products.pdf
8+
9+
[Parameters]
10+
CategoryNameReportParameter=Grains/Cereals

0 commit comments

Comments
 (0)