Skip to content

Commit e425a69

Browse files
committed
delphi: comments
1 parent 1dec711 commit e425a69

1 file changed

Lines changed: 7 additions & 22 deletions

File tree

Delphi/PDFReportGenerator.dpr

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,20 @@ begin
3838
try
3939
// Assign a database name matching the name specified in the report layout
4040
AConnection.DisplayName := 'NWindConnectionString';
41-
// Assign a connection string to use the local SQLite database
41+
// Assign a connection string required to use the local SQLite database
4242
AConnection.ConnectionString := 'XpoProvider=SQLite; Data Source=..\nwind.db; Mode=ReadOnly';
4343

4444
// Step 3: Define Report Parameter Values
4545
AReport.LoadParametersFromReport;
46-
// Set the value of the "OrderIdParameter" parameter in the report layout
46+
// Set the "OrderIdParameter" value in the report layout
4747
AReport.Parameters['OrderIdParameter'].Value := AOrderID;
4848

4949
// Step 4: Export a report to PDF
5050
AStream := TMemoryStream.Create;
5151
try
52-
// Export a report to PDF format and save it to a memory stream
52+
// Export a report to a memory stream in the PDF format
5353
AReport.ExportToPDF(AStream);
54-
// Write the content of the memory stream to a file
54+
// Save memory stream content to a file
5555
AOutputFileName := '..\Order_' + AOrderID + '.pdf';
5656
AStream.SaveToFile(AOutputFileName);
5757
Writeln('Report saved to: ', AOutputFileName);
@@ -68,27 +68,12 @@ end;
6868

6969
// The helper application entry point that parses command-line parameters and calls the export procedure
7070
begin
71-
AOrderID := ''; // Initialize as empty
72-
// Parse command-line parameters in the format "key=value"
73-
for i := 1 to ParamCount do
71+
if ParamCount < 1 then
7472
begin
75-
if ParamStr(i).Contains('=') then
76-
begin
77-
AParameter := SplitString(ParamStr(i), '=');
78-
Key := AParameter[0].ToLower;
79-
Value := AParameter[1];
80-
81-
if Key = 'orderid' then
82-
AOrderID := Value;
83-
end;
84-
end;
85-
86-
// Check if AOrderID is provided
87-
if AOrderID.IsEmpty then
88-
begin
89-
Writeln('Error: OrderID parameter is required. For example: PDFReportGenerator.exe orderid=11077');
73+
Writeln('Error: OrderID parameter is required. For example: PDFReportGenerator.exe 11077');
9074
Halt(1); // Exit with error code 1
9175
end;
9276

77+
AOrderID := ParamStr(1); // Read the first parameter as OrderID
9378
ExportReportToPdf(AOrderID);
9479
end.

0 commit comments

Comments
 (0)