From f107619061a9899041e65984855c75d30fb3b56d Mon Sep 17 00:00:00 2001 From: jesus Date: Mon, 25 May 2020 16:57:23 +0000 Subject: [PATCH] LazReport: moved printer initial setup out of unit's initialization, patch from Zdravko Gabrovski with changes, fix issue #37065 git-svn-id: trunk@63221 - --- components/lazreport/source/lr_prntr.pas | 36 ++++++++++++++++-------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/components/lazreport/source/lr_prntr.pas b/components/lazreport/source/lr_prntr.pas index f1813d42a0..61bae28e61 100644 --- a/components/lazreport/source/lr_prntr.pas +++ b/components/lazreport/source/lr_prntr.pas @@ -71,14 +71,16 @@ type property PrinterIndex: Integer read FPrinterIndex write SetPrinterIndex; end; -var - Prn: TfrPrinter; +function Prn : TfrPrinter; const MAX_TYP_KNOWN = 118; implementation +var + GlobalPrn: TfrPrinter = nil; + type TPaperInfo = record Typ: Integer; @@ -363,6 +365,25 @@ const // {$ENDIF} + + +function Prn: TfrPrinter; +begin +if Assigned( GlobalPrn ) then + Exit( GlobalPrn ); + + GlobalPrn := TfrPrinter.Create; + try + GlobalPrn.Printer:=Printer; + except + on E: Exception do begin + debugln('lazreport: unit lr_prntr: ',E.Message); + end; + end; + Exit( GlobalPrn ); +end; + + {----------------------------------------------------------------------------} constructor TfrPrinter.Create; var @@ -1245,16 +1266,9 @@ end; {----------------------------------------------------------------------------} initialization - Prn := TfrPrinter.Create; - try - Prn.Printer:=Printer; - except - on E: Exception do begin - debugln('lazreport: unit lr_prntr: ',E.Message); - end; - end; finalization - Prn.Free; + if Assigned( GlobalPrn ) then + GlobalPrn.Free; end.