Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Impresión (https://www.clubdelphi.com/foros/forumdisplay.php?f=4)
-   -   Determinar puerto de impresión (https://www.clubdelphi.com/foros/showthread.php?t=53116)

MAXIUM 11-02-2008 17:06:06

Determinar puerto de impresión
 
Hola, quisiera saber que tipo de puerto usa la impresora determinada. Uso el siguiente código pero al mostara el tipo de puerto me aparece en blanco.

Código Delphi [-]
Uses Printers;

Type
      TPrinterDevice = Class Driver, Device, Port: String;

TForm1.Button1Click(Sender:TObject);
Begin
    // Para obtener el nombre de la impresora.   
       Label1.Caption:= TPrinterDevice(Printer.Printers.Objects[Printer.PrinterIndex].Device;

    // Para obtener el tipo de puerto.   
       Label2.Caption:= TPrinterDevice(Printer.Printers.Objects[Printer.PrinterIndex].Port;
End;

cHackAll 12-02-2008 03:41:11

Código Delphi [-]
uses WinSpool;
 
procedure TForm1.Button1Click(Sender: TObject);
var
 Size, Count, Index: Cardinal;
 Items: array [0..2047] of TPrinterInfo5;
 Default: array [0..255] of Char;
begin
 EnumPrinters(PRINTER_ENUM_LOCAL + PRINTER_ENUM_CONNECTIONS, nil, 5, @Items, SizeOf(Items), Size, Count);
 GetProfileString('windows', 'device', '', @Default, SizeOf(Default) - 1);
 Index := 0; while not (Default[Index] in [#0, ',']) do Inc(Index);
 Default[Index] := #0;
 for Index := 0 to Count - 1 do
  if not LongBool(lstrcmpi(@Default, Items[Index].pPrinterName)) then
   MessageBox(Handle, Items[Index].pPortName, nil, 0);
end;

MAXIUM 12-02-2008 15:38:44

Muchisimas gracias, funciona de maravillas.


La franja horaria es GMT +2. Ahora son las 19:04:03.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi