Although in docs there is a sample of concating reports – it is a buggy way for some reasons…
Problem 1
i’ve already posted that function that concat reports but it well concats dynamically generated reports, if one of them in design time than it concats it unprepared i.e. empty and that is the problem for the moment
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
procedure TReportSettingsEventsForm.concatReports(var AresultReport: TfrxReport; a: array of TfrxReport); var i: Integer; ms: TMemoryStream; guid: TGUID; filename: string; begin for i := Low(a) to High(a) do begin ms := TMemoryStream.Create(); try Createguid(guid); filename := guid.ToString() + '.fr3'; // a[i].PrepareReport(false); a[i].SaveToFile(filename); AresultReport.LoadFromFile(filename); AresultReport.PrepareReport(false); finally ms.free(); if TFile.Exists(filename) then TFile.Delete(filename); end; end; end; |
Problem 2
After concat i wanted to save it lets say in blob… using savetofile() function, but ! Concated report doesn’t work well also… So i decided to batch reports by streams…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
procedure TReportSettingsEventsForm.batchReports(a: TArray<TfrxReport>; batchFilePath: string); var i: Integer; fs_out, fsReport: TFileStream; filename: string; dReportPathes: TDictionary<integer, string>; reportCount: integer; reportSize: Int64; begin fs_out := TFile.Create(batchFilePath, fmCreate); try reportCount := Length(a); fs_out.WriteBuffer(reportCount, SizeOf(integer)); // report count for i := 0 to High(a) do // saveReports and measure their sizes begin filename := TPath.GetRandomFileName() + '.fr3'; a[i].SaveToFile(filename); fsReport := TFileStream.Create(filename, fmOpenRead); try fsReport.Position := 0; reportSize := fsReport.Size; fs_out.WriteBuffer(reportSize, SizeOf(Int64)); // write size fs_out.CopyFrom(fsReport, fsReport.Size); // write report finally fsReport.Free; if TFile.Exists(filename) then TFile.Delete(filename); end; end; finally fs_out.Free(); end; end; |
Unbatch reports…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
procedure TReportSettingsEventsForm.unBatchReports(var a: TArray<TfrxReport>; batchFilePath: string); var i: Integer; fs, fsReport: TFileStream; filename: string; guid: TGuid; reportCount: integer; reportSize: Int64; begin fs := TFileStream.Create(batchFilePath, fmOpenRead); fs.Position := 0; SetLength(a, 0); try fs.ReadBuffer(reportCount, SizeOf(integer)); // report count for i := 0 to reportCount - 1 do begin //read size fs.ReadBuffer(reportSize, SizeOf(int64)); CreateGUID(guid); filename := TPath.GetRandomFileName() + '.fr3'; fsReport := TFileStream.Create(filename, fmCreate); try fsReport.Position := 0; fsReport.CopyFrom(fs, reportSize); SetLength(a, Length(a) + 1); a[i] := TfrxReport.Create(Self); fsReport.Position := 0; a[i].LoadFromStream(fsReport); //a[i].PrepareReport(false); //a[i].ShowPreparedReport(); finally fsReport.Free(); if TFile.Exists(filename) then TFile.Delete(filename); end; { a[i].SaveToFile('123afterRead.fr3'); a[i].PrepareReport(false); a[i].ShowPreparedReport(); } end; finally fs.Free(); end; end; |
Conclusion is concating reports – buggy way…