From a77e88fed30d0f5d4e2a0c63a2999ef63eb15f02 Mon Sep 17 00:00:00 2001 From: jesus Date: Mon, 21 May 2012 17:10:46 +0000 Subject: [PATCH] LazReport, lrcodereport: fix problem with slow generation of pages on second batch, sample now ask for target pdf filename, from Julio Jimenez Borreguero git-svn-id: trunk@37381 - --- .../addons/lrcodereport/lr_codereport.pas | 7 +-- .../addons/lrcodereport/sample/main.lfm | 31 +++++++--- .../addons/lrcodereport/sample/main.pas | 56 +++++++++++++------ 3 files changed, 64 insertions(+), 30 deletions(-) diff --git a/components/lazreport/source/addons/lrcodereport/lr_codereport.pas b/components/lazreport/source/addons/lrcodereport/lr_codereport.pas index 91e5821cb5..d8a132bf97 100644 --- a/components/lazreport/source/addons/lrcodereport/lr_codereport.pas +++ b/components/lazreport/source/addons/lrcodereport/lr_codereport.pas @@ -281,7 +281,7 @@ end; procedure TlrCodeReport.SetActivePage(APage: integer); begin - if APage in [1 .. PageCount] then + if (APage >= 1) and (APage <= PageCount) then ActivePage := APage - 1 else raise Exception.CreateFmt(sErrorOccured, [self.ClassName]); @@ -516,7 +516,6 @@ var aLine: TfrLineView; begin aLine := TfrLineView.Create; - aLine.CreateUniqueName; aLine.Left := X * XRatio; aLine.Top := Y * YRatio; aLine.Width := W * XRatio; @@ -553,7 +552,6 @@ var AText: TfrMemoview; begin AText := TfrMemoView.Create; - AText.CreateUniqueName; AText.Left := X * XRatio; AText.Top := Y * YRatio; AText.Width := W * XRatio; @@ -673,7 +671,6 @@ var APicture: TfrPictureView; begin APicture := TfrPictureView.Create; - APicture.CreateUniqueName; APicture.Left := X * XRatio; APicture.Top := Y * YRatio; APicture.Width := W * XRatio; @@ -691,7 +688,6 @@ var AShape: TfrShapeView; begin AShape := TfrShapeView.Create; - AShape.CreateUniqueName; AShape.Left := X * XRatio; AShape.Top := Y * YRatio; AShape.Width := W * XRatio; @@ -758,7 +754,6 @@ var ABarCode: TfrBarCodeView; begin ABarCode := TfrBarCodeView.Create; - ABarCode.CreateUniqueName; ABarCode.Left := X * XRatio; ABarCode.Top := Y * YRatio; ABarCode.Width := W * XRatio; diff --git a/components/lazreport/source/addons/lrcodereport/sample/main.lfm b/components/lazreport/source/addons/lrcodereport/sample/main.lfm index 712e3d6ecc..c48c112db3 100644 --- a/components/lazreport/source/addons/lrcodereport/sample/main.lfm +++ b/components/lazreport/source/addons/lrcodereport/sample/main.lfm @@ -1,18 +1,19 @@ object Form1: TForm1 Left = 296 - Height = 397 + Height = 402 Top = 163 Width = 458 Caption = 'Form1' - ClientHeight = 397 + ClientHeight = 402 ClientWidth = 458 LCLVersion = '1.1' object Image1: TImage Left = 8 - Height = 300 + Height = 297 Top = 8 Width = 443 Anchors = [akTop, akLeft, akRight, akBottom] + Center = True Picture.Data = { 1754506F727461626C654E6574776F726B47726170686963EB66010089504E47 0D0A1A0A0000000D49484452000001C20000012C0802000000DF3424E0000000 @@ -2894,23 +2895,33 @@ object Form1: TForm1 object Button1: TButton Left = 8 Height = 25 - Top = 320 + Top = 312 Width = 443 Anchors = [akLeft, akRight, akBottom] - Caption = 'Execute Report' + Caption = 'Execute and Show Report' OnClick = Button1Click TabOrder = 0 end object Button2: TButton Left = 8 Height = 25 - Top = 360 + Top = 341 Width = 443 Anchors = [akLeft, akRight, akBottom] Caption = 'Export to PDF' OnClick = Button2Click TabOrder = 1 end + object Button3: TButton + Left = 8 + Height = 25 + Top = 368 + Width = 443 + Anchors = [akLeft, akRight, akBottom] + Caption = 'Print full report' + OnClick = Button3Click + TabOrder = 2 + end object frTNPDFExport1: TfrTNPDFExport left = 184 top = 152 @@ -2923,9 +2934,13 @@ object Form1: TForm1 left = 184 top = 208 end - object Report: TlrCodeReport - OnBeginReport = ReportBeginReport + object CodeReport1: TlrCodeReport + OnBeginReport = CodeReport1BeginReport left = 40 top = 152 end + object SaveDialog1: TSaveDialog + left = 304 + top = 152 + end end diff --git a/components/lazreport/source/addons/lrcodereport/sample/main.pas b/components/lazreport/source/addons/lrcodereport/sample/main.pas index d33d1bcf7e..50722ccd1c 100644 --- a/components/lazreport/source/addons/lrcodereport/sample/main.pas +++ b/components/lazreport/source/addons/lrcodereport/sample/main.pas @@ -6,7 +6,7 @@ interface uses Classes, SysUtils, LR_Class, LR_Shape, LR_BarC, lr_e_pdf, Forms, - Controls, Graphics, Dialogs, ExtCtrls, StdCtrls, LR_CodeReport; + Graphics, Dialogs, ExtCtrls, StdCtrls, LR_CodeReport; type @@ -15,14 +15,17 @@ type TForm1 = class(TForm) Button1: TButton; Button2: TButton; + Button3: TButton; frBarCodeObject1: TfrBarCodeObject; frShapeObject1: TfrShapeObject; frTNPDFExport1: TfrTNPDFExport; Image1: TImage; - Report: TlrCodeReport; + CodeReport1: TlrCodeReport; + SaveDialog1: TSaveDialog; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); - procedure ReportBeginReport(Sender: TObject); + procedure Button3Click(Sender: TObject); + procedure CodeReport1BeginReport(Sender: TObject); private { private declarations } public @@ -40,26 +43,40 @@ implementation procedure TForm1.Button1Click(Sender: TObject); begin - //report.RunReport; - if Report.PageCount = 0 then + with CodeReport1 do begin - ReportBeginReport(report); + Report.Clear; // restart the report (delete existing pages) + RunReport; // execute code and show report end; - Report.Report.ShowReport; end; procedure TForm1.Button2Click(Sender: TObject); begin - //direct export to PDF. Set the desired destination file. - if Report.PageCount = 0 then - begin - ReportBeginReport(report); - Report.Report.PrepareReport; - end; - Report.Report.ExportTo(TfrTNPDFExportFilter, '/tmp/generated-pdf.pdf'); + SaveDialog1.FileName := 'mycodereport.pdf'; + if SaveDialog1.Execute then + with CodeReport1 do + begin + Report.Clear; // reset report + CodeReport1BeginReport(CodeReport1); // execute code + Report.PrepareReport; + Report.ExportTo(TfrTNPDFExportFilter, SaveDialog1.FileName); + end; end; -procedure TForm1.ReportBeginReport(Sender: TObject); +procedure TForm1.Button3Click(Sender: TObject); +begin + with CodeReport1 do + begin + Report.Clear; // reset report + CodeReport1BeginReport(CodeReport1); // execute code + Report.PrepareReport; + Report.PrintPreparedReport('', 1); // empty string print all the pages + // '1-5' print pages from 1 to 5 + // '1,3,5' print pages 1, 3 and 5 + end; +end; + +procedure TForm1.CodeReport1BeginReport(Sender: TObject); var BoxText: TlrTextRectStyle; n: integer; @@ -265,8 +282,15 @@ begin TextOutXY(X, GetPageHeight - PageMargin.Bottom, Format('Page %d of %d', [GetActivePage, PageCount]), taRightJustify); end; - end; + + // For a really big report (10015 pages), try uncommenting next lines + + //for n:= 1 to 10000 do + //begin + // NewPage; + // TextOut(Format('Page %d', [GetActivePage])); + //end; end; end;