Board index » delphi » Help with TPrinter.GetPrinter and NT

Help with TPrinter.GetPrinter and NT

Art,

Quote
Art wrote:
> Hi
> I am having trouble with getting the printer "port" in NT with
> TPrinter.GetPrinter.  The procedure correctly identifies the printer name,
> but the port parameter is left as an empty string. The printer name is
> 'Reception'. Is there an alternative method of getting the
> Printer.PrinterIndex's port?

I am not sure I understand your question. If you want the Printer Port then
this will do

uses
  Printers,Winspool;

function GetPrinterPort(PrinterName: String): String;
var
  PrinterHandle: Cardinal;
  Struct: PPrinterInfo5;
  Needed: DWORD;
begin
  If OpenPrinter(PChar(Printer.Printers[0]), PrinterHandle, nil) then
  try
    GetPrinter(PrinterHandle, 5, nil, 0, @Needed);

    GetMem(Struct, Needed);

    try
      If GetPrinter(PrinterHandle, 5, Struct, Needed, @Needed) then
      begin
        Result := Struct^.pPortName;
      end
      else RaiseLastWin32Error;
    finally
      FreeMem(Struct);
    end;
  finally
    ClosePrinter(PrinterHandle)
  end
  else RaiseLastWin32Error;
end;

Quote

> Thanks in advance,

> Artur.

Dr. Delphi
 

Re:Help with TPrinter.GetPrinter and NT


Thanks
This will get around the problem for me, but I still think there is
something wrong with Delphi 4's (4.03)implementation of TPrinter

Example: In the Evaluate/Modify dialog, I have accessed the
TPrinter.Printers.Objects array:

In Windows 98:
TPrinterDevice(Printer.Printers.Objects[0])
Result: ('','Reception','LPT1:')

In Windows NT:
TPrinterDevice(Printer.Printers.Objects[0])
Result: ('','Reception','')   <---  Why is this blank, dammit!!

Anyway, thanks again...
I will try to not think about this problem anymore.

Artur.

Re:Help with TPrinter.GetPrinter and NT


Quote
> This will get around the problem for me, but I still think there is
> something wrong with Delphi 4's (4.03)implementation of TPrinter

Well, it seems to fail to take into account some subtle differences
in the EnumPrinters API functions behaviour on NT and Win9x.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Other Threads