Delphi 5 & Printers.pas

There are all kinds of bugs in the printers.pas module in Delphi 5. Over the years I’ve been fixing them as I find them and I figured it is time that I documented what I know. The problems that I have encountered are:

  • SetToDefaultPrinter was being called at inappropriate times when setting a new printer via PrinterIndex.
  • SetPrinter was not being called when setting a new printer via PrinterIndex. This resulted in the old printer’s properties being retained.
  • SetToDefaultPrinter was using obsolete methods of obtaining the default printer name. This was causing problems on server class operating systems.
  • Dialogs.GetPrinter was throwing an access violation if long printer names (> 80 bytes) where encountered.

You can find versions of printers.pas and dialogs.pas with fixes for these problems at:

Changed code is flagged with SWB at the end of the line.


3 Responses to “Delphi 5 & Printers.pas”

  1. John Friel Says:

    Do you have a patched Delphi XE Printers.pas that is unicode friendly? Thanks in advance.

  2. lnsgod Says:

    Nope. Sorry. A lot of this stuff should be fixed in XE anyway.

  3. John Friel Says:

    Thanks anyway Steve. I am running into the “no default printer” issue when my application is run in AppV mode on VMs. The virtual machine that it is running on may or may not have a default printer assigned. I’ll see if I can just patch my copy from your notes.

Leave a Reply