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

x
?
Solved

Delphi Getprinter - HP multi tray

Posted on 2007-10-05
3
Medium Priority
?
1,622 Views
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 );
type  
  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;
Var
  Device, Driver, Port: Array [0..255] of Char;
  hDevMode: THandle;
  i, numBinNames, numBins, temp: Integer;
  pBinNames: PBinnameArray;
  pBins: PBinArray;
begin
  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
  begin
    raise Exception.Create(
            'DeviceCapabilities reports different number of bins and '+
            'bin names!');
  end;

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

Accepted Solution

by:
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.

http://61.153.235.142/sz/xs/delphi/3/Quick%20Report%20FAQ(4).htm

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

Let me know if this helps.
0
 
LVL 1

Expert Comment

by:Computer101
ID: 21216616
Forced accept.

Computer101
EE Admin
0

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