View Issue Details

IDProjectCategoryView StatusLast Update
0023726LazarusPrinterpublic2014-01-02 11:25
ReporterPetr-KAssigned ToJesus Reyes 
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Platformwin32OSWinXPOS Version
Product VersionProduct BuildSVN #39862 
Target Version1.3 (SVN)Fixed in Version1.3 (SVN) 
Summary0023726: Error in Printer.Free on app finalization
DescriptionIf win32 application uses Printers unit and Printers are __not initialized__,
then I get runtime error 210 when program is finishing.

Reason:
Printers.Free calls TWinPrinter.DoResetPrintersList:
Loop "for i:=0 to Printers.Count-1 do" causes call TPrinter.GetPrinters
and because fPrintersValid = false printers initialization starts.

But program is almost terminated and initialization fails in some Canvas call.

Printers initialization at program termination is bad.
I added protected function TPrinter.PrintersValid to access private TPrinter.fPrintersValid and used it to do ResetPrintersList only if Printers are valid.

Patch is in the attachement.
TagsNo tags attached.
Fixed in Revision43024
LazTarget1.2
WidgetsetWin32/Win64
Attached Files
  • printers.patch (1,337 bytes)
    Index: lcl/printers.pas
    ===================================================================
    --- lcl/printers.pas	(revision 39862)
    +++ lcl/printers.pas	(working copy)
    @@ -249,6 +249,7 @@
          procedure RawModeChanging; virtual;
          procedure PrinterSelected; virtual;
          function  DoGetDefaultCanvasClass: TPrinterCanvasRef; virtual;
    +     function PrintersValid: boolean;
       public
          constructor Create; virtual;
          destructor Destroy; override;
    @@ -548,6 +549,11 @@
       result := TPrinterCanvas;
     end;
     
    +function TPrinter.PrintersValid: boolean;
    +begin
    +  Result := fPrintersValid;
    +end;
    +
     //Get current copies number
     function TPrinter.GetCopies: Integer;
     Var i : Integer;
    Index: components/printers/win32/winprinters.inc
    ===================================================================
    --- components/printers/win32/winprinters.inc	(revision 39862)
    +++ components/printers/win32/winprinters.inc	(working copy)
    @@ -581,12 +581,13 @@
     var i   : Integer;
         Obj : TObject;
     begin
    -  for i:=0 to Printers.Count-1 do
    -  begin
    -    Obj:=Printers.Objects[i];
    -    Printers.Objects[i]:=nil;
    -    Obj.Free;
    -  end;
    +  if PrintersValid then
    +    for i:=0 to Printers.Count-1 do
    +    begin
    +      Obj:=Printers.Objects[i];
    +      Printers.Objects[i]:=nil;
    +      Obj.Free;
    +    end;
       inherited DoResetPrintersList;
     end;
     
    
    printers.patch (1,337 bytes)

Relationships

related to 0023859 closedJesus Reyes Runtime error in Printer.Free on program finalization at Win32 

Activities

2013-01-22 14:52

 

printers.patch (1,337 bytes)
Index: lcl/printers.pas
===================================================================
--- lcl/printers.pas	(revision 39862)
+++ lcl/printers.pas	(working copy)
@@ -249,6 +249,7 @@
      procedure RawModeChanging; virtual;
      procedure PrinterSelected; virtual;
      function  DoGetDefaultCanvasClass: TPrinterCanvasRef; virtual;
+     function PrintersValid: boolean;
   public
      constructor Create; virtual;
      destructor Destroy; override;
@@ -548,6 +549,11 @@
   result := TPrinterCanvas;
 end;
 
+function TPrinter.PrintersValid: boolean;
+begin
+  Result := fPrintersValid;
+end;
+
 //Get current copies number
 function TPrinter.GetCopies: Integer;
 Var i : Integer;
Index: components/printers/win32/winprinters.inc
===================================================================
--- components/printers/win32/winprinters.inc	(revision 39862)
+++ components/printers/win32/winprinters.inc	(working copy)
@@ -581,12 +581,13 @@
 var i   : Integer;
     Obj : TObject;
 begin
-  for i:=0 to Printers.Count-1 do
-  begin
-    Obj:=Printers.Objects[i];
-    Printers.Objects[i]:=nil;
-    Obj.Free;
-  end;
+  if PrintersValid then
+    for i:=0 to Printers.Count-1 do
+    begin
+      Obj:=Printers.Objects[i];
+      Printers.Objects[i]:=nil;
+      Obj.Free;
+    end;
   inherited DoResetPrintersList;
 end;
 
printers.patch (1,337 bytes)

Petr-K

2013-02-08 17:15

reporter   ~0065585

I think, that bug 0023859 relates to this one.

Jesus Reyes

2013-10-09 07:50

developer   ~0070690

I'm sorry, I missed this report while fixing another one (0023026) I fixed the problem with another approach.

Petr-K

2014-01-02 11:25

reporter   ~0072172

Resolved

Issue History

Date Modified Username Field Change
2013-01-22 14:52 Petr-K New Issue
2013-01-22 14:52 Petr-K File Added: printers.patch
2013-01-22 14:52 Petr-K Widgetset => Win32/Win64
2013-02-03 01:56 Jesus Reyes Assigned To => Jesus Reyes
2013-02-03 01:56 Jesus Reyes Status new => assigned
2013-02-08 17:15 Petr-K Note Added: 0065585
2013-02-08 17:32 Zeljan Rikalo Relationship added related to 0023859
2013-10-09 07:50 Jesus Reyes Fixed in Revision => 43024
2013-10-09 07:50 Jesus Reyes LazTarget => 1.2
2013-10-09 07:50 Jesus Reyes Note Added: 0070690
2013-10-09 07:50 Jesus Reyes Status assigned => resolved
2013-10-09 07:50 Jesus Reyes Fixed in Version => 1.3 (SVN)
2013-10-09 07:50 Jesus Reyes Resolution open => fixed
2013-10-09 07:50 Jesus Reyes Target Version => 1.3 (SVN)
2014-01-02 11:25 Petr-K Note Added: 0072172
2014-01-02 11:25 Petr-K Status resolved => closed