Random Errors "Printer Wrong" on Win2K8R2

I recently changed the print code for automatic printing to TPrinter. (An old solution, writing text directly on a network printer device worked without error for many years.)

The application is written in Delphi 2009 Enterprise and runs continuously in a user session (and not as a service). At regular intervals, the application scans the database for new documents, creates text for printing and sends it to the printer.

Before printing, the code sets the printer index:

PrinterToUse := Printer.Printers.IndexOf(MyPrinterName); if PrinterToUse > -1 then begin Printer.PrinterIndex := PrinterToUse; end else begin Assert(False, Format('Printer %s not found', [MyPrinterName])); end; 

Where MyPrinterName can be, for example, \\PRINTSERVER\PR001 . For my testing phase, I use one locally installed printer with a new printing method, so the printer name is always the same.

At random intervals, printing with the EPrinter error "selected printer is not valid".

If this exception occurs, printing the document fails - I added a workaround that uses the 'legacy' printing method when this happens.

I suspect that there may be errors in the VCL printer unit. In Quality Central, I found only one related entry - http://qc.embarcadero.com/wc/qcmain.aspx?d=127390 . I could try the new version of Delphi, if the problem persists, it could be a problem with the printer driver. Updating printer drivers is also an option I should try.

I will also improve error handling and try printing once or twice if an error occurs.

Is there any other experience with this random error and was there a solution?

+4
source share

Source: https://habr.com/ru/post/1232882/


All Articles