Trying to access the printer settings and switch bins while printing duplex forms.
Have tried the code from here thread102-1079747. Printer does not switch bins and will not print duplex.
My code.
procedure TDecPageModule.PrintForms;
var
pDevice,pDriver,pPort : array [0..255] of Char;
S : string;
hDeviceMode : THandle;
procedure ChangePrinterBin(ToBin: Integer);
var
ADevice, ADriver, APort: array [0..255] of Char;
DeviceHandle: THandle;
DevMode: PDeviceMode; // A Pointer to a TDeviceMode structure
begin
(* First obtain a handle to the TPrinter's DeviceMode structure *)
Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
(* If DeviceHandle is still 0, then the driver was not loaded. Set
the printer index to force the printer driver to load making the
handle available *)
if DeviceHandle = 0 then
begin
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(pDevice, pDriver, pPort, DeviceHandle);
end;
(* If DeviceHandle is still 0, then an error has occurred. Otherwise,
use GlobalLock() to get a pointer to the TDeviceMode structure *)
if DeviceHandle = 0 then
Raise Exception.Create('Could Not Initialize TDeviceMode structure')
else
DevMode := GlobalLock(DeviceHandle);
with DevMode^ do
begin
dmFields := DM_DEFAULTSOURCE;
dmDefaultSource := ToBin;
end;
if not (DeviceHandle = 0) then
GlobalUnlock(DeviceHandle);
end;
procedure ChangePrinterDuplex(ToMode: Integer);
var
ADevice, ADriver, APort: array [0..255] of Char;
DeviceHandle: THandle;
DevMode: PDeviceMode; // A Pointer to a TDeviceMode structure
begin
(* First obtain a handle to the TPrinter's DeviceMode structure *)
Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
(* If DeviceHandle is still 0, then the driver was not loaded. Set
the printer index to force the printer driver to load making the
handle available *)
if DeviceHandle = 0 then
begin
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(pDevice, pDriver, pPort, DeviceHandle);
end;
(* If DeviceHandle is still 0, then an error has occurred. Otherwise,
use GlobalLock() to get a pointer to the TDeviceMode structure *)
if DeviceHandle = 0 then
Raise Exception.Create('Could Not Initialize TDeviceMode structure')
else
DevMode := GlobalLock(DeviceHandle);
with DevMode^ do
begin
dmFields := DM_DUPLEX;
dmDuplex := ToMode;
end;
if not (DeviceHandle = 0) then
GlobalUnlock(DeviceHandle);
end;
procedure ChangeOptions(BinNum,DuplexMode : smallint);
begin
(* First obtain a handle to the TPrinter's DeviceMode structure *)
Printer.GetPrinter(pDevice, pDriver, pPort, DeviceHandle);
ChangePrinterBin(BinNum);
ChangePrinterDuplex(DuplexMode);
end;
Need help figuring out what I'm doing wrong
Have tried the code from here thread102-1079747. Printer does not switch bins and will not print duplex.
My code.
procedure TDecPageModule.PrintForms;
var
pDevice,pDriver,pPort : array [0..255] of Char;
S : string;
hDeviceMode : THandle;
procedure ChangePrinterBin(ToBin: Integer);
var
ADevice, ADriver, APort: array [0..255] of Char;
DeviceHandle: THandle;
DevMode: PDeviceMode; // A Pointer to a TDeviceMode structure
begin
(* First obtain a handle to the TPrinter's DeviceMode structure *)
Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
(* If DeviceHandle is still 0, then the driver was not loaded. Set
the printer index to force the printer driver to load making the
handle available *)
if DeviceHandle = 0 then
begin
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(pDevice, pDriver, pPort, DeviceHandle);
end;
(* If DeviceHandle is still 0, then an error has occurred. Otherwise,
use GlobalLock() to get a pointer to the TDeviceMode structure *)
if DeviceHandle = 0 then
Raise Exception.Create('Could Not Initialize TDeviceMode structure')
else
DevMode := GlobalLock(DeviceHandle);
with DevMode^ do
begin
dmFields := DM_DEFAULTSOURCE;
dmDefaultSource := ToBin;
end;
if not (DeviceHandle = 0) then
GlobalUnlock(DeviceHandle);
end;
procedure ChangePrinterDuplex(ToMode: Integer);
var
ADevice, ADriver, APort: array [0..255] of Char;
DeviceHandle: THandle;
DevMode: PDeviceMode; // A Pointer to a TDeviceMode structure
begin
(* First obtain a handle to the TPrinter's DeviceMode structure *)
Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
(* If DeviceHandle is still 0, then the driver was not loaded. Set
the printer index to force the printer driver to load making the
handle available *)
if DeviceHandle = 0 then
begin
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(pDevice, pDriver, pPort, DeviceHandle);
end;
(* If DeviceHandle is still 0, then an error has occurred. Otherwise,
use GlobalLock() to get a pointer to the TDeviceMode structure *)
if DeviceHandle = 0 then
Raise Exception.Create('Could Not Initialize TDeviceMode structure')
else
DevMode := GlobalLock(DeviceHandle);
with DevMode^ do
begin
dmFields := DM_DUPLEX;
dmDuplex := ToMode;
end;
if not (DeviceHandle = 0) then
GlobalUnlock(DeviceHandle);
end;
procedure ChangeOptions(BinNum,DuplexMode : smallint);
begin
(* First obtain a handle to the TPrinter's DeviceMode structure *)
Printer.GetPrinter(pDevice, pDriver, pPort, DeviceHandle);
ChangePrinterBin(BinNum);
ChangePrinterDuplex(DuplexMode);
end;
Need help figuring out what I'm doing wrong