[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Delphi Getprinter - HP multi tray

Posted on 2007-10-05
Medium Priority
Last Modified: 2013-12-15
We have a problem with HP Multi-tray printers, Assistance Urgently required.

In a stand alone application the code below works fine for all printers& however when the code below is used within our main application with the default printer set to a HP-multi tray, any reference to he printer object causes the CPU window to be popped up (in the dev environment) although an exception is not thrown.

A subsequent call to GetPrinter again displays the CPU window.

A call to DeviceCapabilities then returns the fail code, -1.

We also use QuickReports so on the stand alone test harness application we tried various tests, including together with quickreport components to see if it falls over.
And in our main application we have tested the code below at the start of our application before anything else is called.  

Note. We are testing this using a HP Laserjet 1320TN, 4 of our clients, using our application are using other HP Multi-tray printers and have this problem.

We are puzzled about:
1). Why the CPU window pops up in the development environment (Delphi 7 Studio Professional) when an exception is not thrown
2). Why the same code works in the test environment and not in the live app
3). Why it is only HP printers that seem to cause the problem

The code follows:
procedure Tform1.GetBinnames2( sl: TStrings );
  TBinName      = array [0..23] of Char;
  TBinNameArray = array [1..High(Integer) div SizeOf(TBinName)] of TBinName;
  PBinnameArray = ^TBinNameArray;
  TBinArray     = array [1..High(Integer) div SizeOf(Word)] of Word;
  PBinArray     = ^TBinArray;
  Device, Driver, Port: Array [0..255] of Char;
  hDevMode: THandle;
  i, numBinNames, numBins, temp: Integer;
  pBinNames: PBinnameArray;
  pBins: PBinArray;
  Printer.PrinterIndex := -1;
  Printer.GetPrinter(Device, Driver, Port, hDevmode);
  numBinNames :=
    WinSpool.DeviceCapabilities( Device, Port, DC_BINNAMES, Nil, Nil );
  numBins :=
    WinSpool.DeviceCapabilities( Device, Port, DC_BINS, Nil, Nil );
  If numBins <> numBinNames then
    raise Exception.Create(
            'DeviceCapabilities reports different number of bins and '+
            'bin names!');

  If numBinNames > 0 then
    pBins := Nil;
    GetMem( pBinNames, numBinNames * Sizeof( TBinname ));
    GetMem( pBins, numBins * Sizeof(Word));
      WinSpool.DeviceCapabilities( Device, Port, DC_BINNAMES,
                                   Pchar( pBinNames ), Nil);
      WinSpool.DeviceCapabilities( Device, Port, DC_BINS,
                                   Pchar( pBins ), Nil );
      For i:= 1 To numBinNames Do Begin
        temp := pBins^[i];
        sl.addObject( pBinNames^[i], TObject( temp ));
      FreeMem( pBinNames );
      If pBins <> Nil Then
        FreeMem( pBins );
Question by:MartinCasey
LVL 21

Accepted Solution

developmentguru earned 2000 total points
ID: 20034205
A quick search confirmed my suspicions.  The following link is a quick reports FAQ and contains information about printing to a multi try HP priner.  They believe the problem is with the driver trying to reorder the trays.

They did mention that using a different print driver could get you around the issue.

Let me know if this helps.

Expert Comment

ID: 21216616
Forced accept.

EE Admin

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
When I recently replaced my image transfer kit on my office HP color laserjet 5550dn printer, I had a slight problem.  The left bracket that holds the transfer kit got stuck in the upright locked position instead of being at a 45 degree angle facing…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Suggested Courses
Course of the Month19 days, 22 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question