Board index » delphi » TPrinter fails on Printer.BeginDoc

TPrinter fails on Printer.BeginDoc

I have a new HP Photosmart 1100xi printer (latest driver under Windows
NT).  All commercial applications that I have tried (including Delphi)
print to it just fine.  Using TPrinter calls from my own application
(and all other sample TPrinter applications that I have tried, including
efg's Printer Demo #2) causes a halt in the Printer.BeginDoc call.
Tracing into the printers.pas source code shows that the failure is
occurring in the CreateDC function (which is called by

          if FCanvas <> nil then FCanvas.Handle := 0;
          if DC <> 0 then DeleteDC(DC);
          CreateHandleFunc := CreateDC;
    if Assigned(CreateHandleFunc) then
      with TPrinterDevice(Printers.Objects[PrinterIndex]) do
        DC := CreateHandleFunc(PChar(Driver), PChar(Device),
PChar(Port), DevMode);            <<<<<<<< brings up cpu window here
(halts in ntdll.dbgBreakpoint)
        if DC = 0 then RaiseError(SInvalidPrinter);
        if FCanvas <> nil then FCanvas.Handle := DC;

This does not occur when printing to other printers (HP Laserjet 6mp,
Acrobat Distiller or Acrobat PDF Writer).\

This halt only occurs when running the code from within the Delphi IDE.
Running the .exe alone does not cause an exception but printed results
vary with the application.  For example, Printer Demo #2 prints but some
areas of the printed image are incorrect.  My application, which prints
a bitmap using StretchDIB, does not produce any print at all.

Does anyone have any ideas what might be going on?
Is there some example Delphi printing code that does not use TPrinter?


John Williams


Re:TPrinter fails on Printer.BeginDoc

Are you switching printers in pascal code before calling Begin.Doc?
I found the same problem occurred when I did that. After changing
the printer index to the one you want, load the device driver for the
new printer. I've got some code to do that, if needed.


Other Threads