Skip to main content

TdxPrintDevice.FindPrintDevice(PChar,PChar) Method

Returns the index of the printer device by its name and port.

Declaration

function FindPrintDevice(ADevice: PChar; APort: PChar): Integer;

Parameters

Name Type Description
ADevice PChar

The name of the required printer device.

APort PChar

The target printer device port.

Returns

Type Description
Integer

The index of the target printer device (ADevice).

The function returns -1 if no printer with specified parameters is available.

Remarks

Call the FindPrintDevice function to find a printer available for the application. For example, you can assign the obtained index to the PrinterIndex property to set the corresponding printer as active.

Code Example

The following code example sets Microsoft XPS Document Writer as the active printer device for TdxComponentPrinter:

uses
  dxPrnDev;  // This unit declares the dxPrintDevice function

// ...
var
  APrinterIndex: Integer;
begin
  APrinterIndex := dxPrintDevice.FindPrintDevice('Microsoft XPS Document Writer', '');
  if APrinterIndex <> -1 then  // If the specified printer device is available
    dxPrintDevice.PrinterIndex := APrinterIndex;  // Changes the active printer device
end;
See Also