mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-02 21:58:18 +02:00
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 -
This commit is contained in:
parent
ec79d9e28b
commit
a77e88fed3
@ -281,7 +281,7 @@ end;
|
|||||||
|
|
||||||
procedure TlrCodeReport.SetActivePage(APage: integer);
|
procedure TlrCodeReport.SetActivePage(APage: integer);
|
||||||
begin
|
begin
|
||||||
if APage in [1 .. PageCount] then
|
if (APage >= 1) and (APage <= PageCount) then
|
||||||
ActivePage := APage - 1
|
ActivePage := APage - 1
|
||||||
else
|
else
|
||||||
raise Exception.CreateFmt(sErrorOccured, [self.ClassName]);
|
raise Exception.CreateFmt(sErrorOccured, [self.ClassName]);
|
||||||
@ -516,7 +516,6 @@ var
|
|||||||
aLine: TfrLineView;
|
aLine: TfrLineView;
|
||||||
begin
|
begin
|
||||||
aLine := TfrLineView.Create;
|
aLine := TfrLineView.Create;
|
||||||
aLine.CreateUniqueName;
|
|
||||||
aLine.Left := X * XRatio;
|
aLine.Left := X * XRatio;
|
||||||
aLine.Top := Y * YRatio;
|
aLine.Top := Y * YRatio;
|
||||||
aLine.Width := W * XRatio;
|
aLine.Width := W * XRatio;
|
||||||
@ -553,7 +552,6 @@ var
|
|||||||
AText: TfrMemoview;
|
AText: TfrMemoview;
|
||||||
begin
|
begin
|
||||||
AText := TfrMemoView.Create;
|
AText := TfrMemoView.Create;
|
||||||
AText.CreateUniqueName;
|
|
||||||
AText.Left := X * XRatio;
|
AText.Left := X * XRatio;
|
||||||
AText.Top := Y * YRatio;
|
AText.Top := Y * YRatio;
|
||||||
AText.Width := W * XRatio;
|
AText.Width := W * XRatio;
|
||||||
@ -673,7 +671,6 @@ var
|
|||||||
APicture: TfrPictureView;
|
APicture: TfrPictureView;
|
||||||
begin
|
begin
|
||||||
APicture := TfrPictureView.Create;
|
APicture := TfrPictureView.Create;
|
||||||
APicture.CreateUniqueName;
|
|
||||||
APicture.Left := X * XRatio;
|
APicture.Left := X * XRatio;
|
||||||
APicture.Top := Y * YRatio;
|
APicture.Top := Y * YRatio;
|
||||||
APicture.Width := W * XRatio;
|
APicture.Width := W * XRatio;
|
||||||
@ -691,7 +688,6 @@ var
|
|||||||
AShape: TfrShapeView;
|
AShape: TfrShapeView;
|
||||||
begin
|
begin
|
||||||
AShape := TfrShapeView.Create;
|
AShape := TfrShapeView.Create;
|
||||||
AShape.CreateUniqueName;
|
|
||||||
AShape.Left := X * XRatio;
|
AShape.Left := X * XRatio;
|
||||||
AShape.Top := Y * YRatio;
|
AShape.Top := Y * YRatio;
|
||||||
AShape.Width := W * XRatio;
|
AShape.Width := W * XRatio;
|
||||||
@ -758,7 +754,6 @@ var
|
|||||||
ABarCode: TfrBarCodeView;
|
ABarCode: TfrBarCodeView;
|
||||||
begin
|
begin
|
||||||
ABarCode := TfrBarCodeView.Create;
|
ABarCode := TfrBarCodeView.Create;
|
||||||
ABarCode.CreateUniqueName;
|
|
||||||
ABarCode.Left := X * XRatio;
|
ABarCode.Left := X * XRatio;
|
||||||
ABarCode.Top := Y * YRatio;
|
ABarCode.Top := Y * YRatio;
|
||||||
ABarCode.Width := W * XRatio;
|
ABarCode.Width := W * XRatio;
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
object Form1: TForm1
|
object Form1: TForm1
|
||||||
Left = 296
|
Left = 296
|
||||||
Height = 397
|
Height = 402
|
||||||
Top = 163
|
Top = 163
|
||||||
Width = 458
|
Width = 458
|
||||||
Caption = 'Form1'
|
Caption = 'Form1'
|
||||||
ClientHeight = 397
|
ClientHeight = 402
|
||||||
ClientWidth = 458
|
ClientWidth = 458
|
||||||
LCLVersion = '1.1'
|
LCLVersion = '1.1'
|
||||||
object Image1: TImage
|
object Image1: TImage
|
||||||
Left = 8
|
Left = 8
|
||||||
Height = 300
|
Height = 297
|
||||||
Top = 8
|
Top = 8
|
||||||
Width = 443
|
Width = 443
|
||||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||||
|
Center = True
|
||||||
Picture.Data = {
|
Picture.Data = {
|
||||||
1754506F727461626C654E6574776F726B47726170686963EB66010089504E47
|
1754506F727461626C654E6574776F726B47726170686963EB66010089504E47
|
||||||
0D0A1A0A0000000D49484452000001C20000012C0802000000DF3424E0000000
|
0D0A1A0A0000000D49484452000001C20000012C0802000000DF3424E0000000
|
||||||
@ -2894,23 +2895,33 @@ object Form1: TForm1
|
|||||||
object Button1: TButton
|
object Button1: TButton
|
||||||
Left = 8
|
Left = 8
|
||||||
Height = 25
|
Height = 25
|
||||||
Top = 320
|
Top = 312
|
||||||
Width = 443
|
Width = 443
|
||||||
Anchors = [akLeft, akRight, akBottom]
|
Anchors = [akLeft, akRight, akBottom]
|
||||||
Caption = 'Execute Report'
|
Caption = 'Execute and Show Report'
|
||||||
OnClick = Button1Click
|
OnClick = Button1Click
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
end
|
end
|
||||||
object Button2: TButton
|
object Button2: TButton
|
||||||
Left = 8
|
Left = 8
|
||||||
Height = 25
|
Height = 25
|
||||||
Top = 360
|
Top = 341
|
||||||
Width = 443
|
Width = 443
|
||||||
Anchors = [akLeft, akRight, akBottom]
|
Anchors = [akLeft, akRight, akBottom]
|
||||||
Caption = 'Export to PDF'
|
Caption = 'Export to PDF'
|
||||||
OnClick = Button2Click
|
OnClick = Button2Click
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
end
|
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
|
object frTNPDFExport1: TfrTNPDFExport
|
||||||
left = 184
|
left = 184
|
||||||
top = 152
|
top = 152
|
||||||
@ -2923,9 +2934,13 @@ object Form1: TForm1
|
|||||||
left = 184
|
left = 184
|
||||||
top = 208
|
top = 208
|
||||||
end
|
end
|
||||||
object Report: TlrCodeReport
|
object CodeReport1: TlrCodeReport
|
||||||
OnBeginReport = ReportBeginReport
|
OnBeginReport = CodeReport1BeginReport
|
||||||
left = 40
|
left = 40
|
||||||
top = 152
|
top = 152
|
||||||
end
|
end
|
||||||
|
object SaveDialog1: TSaveDialog
|
||||||
|
left = 304
|
||||||
|
top = 152
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, LR_Class, LR_Shape, LR_BarC, lr_e_pdf, Forms,
|
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
|
type
|
||||||
|
|
||||||
@ -15,14 +15,17 @@ type
|
|||||||
TForm1 = class(TForm)
|
TForm1 = class(TForm)
|
||||||
Button1: TButton;
|
Button1: TButton;
|
||||||
Button2: TButton;
|
Button2: TButton;
|
||||||
|
Button3: TButton;
|
||||||
frBarCodeObject1: TfrBarCodeObject;
|
frBarCodeObject1: TfrBarCodeObject;
|
||||||
frShapeObject1: TfrShapeObject;
|
frShapeObject1: TfrShapeObject;
|
||||||
frTNPDFExport1: TfrTNPDFExport;
|
frTNPDFExport1: TfrTNPDFExport;
|
||||||
Image1: TImage;
|
Image1: TImage;
|
||||||
Report: TlrCodeReport;
|
CodeReport1: TlrCodeReport;
|
||||||
|
SaveDialog1: TSaveDialog;
|
||||||
procedure Button1Click(Sender: TObject);
|
procedure Button1Click(Sender: TObject);
|
||||||
procedure Button2Click(Sender: TObject);
|
procedure Button2Click(Sender: TObject);
|
||||||
procedure ReportBeginReport(Sender: TObject);
|
procedure Button3Click(Sender: TObject);
|
||||||
|
procedure CodeReport1BeginReport(Sender: TObject);
|
||||||
private
|
private
|
||||||
{ private declarations }
|
{ private declarations }
|
||||||
public
|
public
|
||||||
@ -40,26 +43,40 @@ implementation
|
|||||||
|
|
||||||
procedure TForm1.Button1Click(Sender: TObject);
|
procedure TForm1.Button1Click(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
//report.RunReport;
|
with CodeReport1 do
|
||||||
if Report.PageCount = 0 then
|
|
||||||
begin
|
begin
|
||||||
ReportBeginReport(report);
|
Report.Clear; // restart the report (delete existing pages)
|
||||||
|
RunReport; // execute code and show report
|
||||||
end;
|
end;
|
||||||
Report.Report.ShowReport;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TForm1.Button2Click(Sender: TObject);
|
procedure TForm1.Button2Click(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
//direct export to PDF. Set the desired destination file.
|
SaveDialog1.FileName := 'mycodereport.pdf';
|
||||||
if Report.PageCount = 0 then
|
if SaveDialog1.Execute then
|
||||||
begin
|
with CodeReport1 do
|
||||||
ReportBeginReport(report);
|
begin
|
||||||
Report.Report.PrepareReport;
|
Report.Clear; // reset report
|
||||||
end;
|
CodeReport1BeginReport(CodeReport1); // execute code
|
||||||
Report.Report.ExportTo(TfrTNPDFExportFilter, '/tmp/generated-pdf.pdf');
|
Report.PrepareReport;
|
||||||
|
Report.ExportTo(TfrTNPDFExportFilter, SaveDialog1.FileName);
|
||||||
|
end;
|
||||||
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
|
var
|
||||||
BoxText: TlrTextRectStyle;
|
BoxText: TlrTextRectStyle;
|
||||||
n: integer;
|
n: integer;
|
||||||
@ -265,8 +282,15 @@ begin
|
|||||||
TextOutXY(X, GetPageHeight - PageMargin.Bottom,
|
TextOutXY(X, GetPageHeight - PageMargin.Bottom,
|
||||||
Format('Page %d of %d', [GetActivePage, PageCount]), taRightJustify);
|
Format('Page %d of %d', [GetActivePage, PageCount]), taRightJustify);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
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;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user