Mega Code Archive

 
Categories / Delphi / Printing
 

Printing to a specific bin

Title: Printing to a specific bin Question: Needed routine to print output to a specific bin on a laser printer. The key to this routine is the DevMode structure, there are several other routines that could be written using this structure. Answer: procedure BinToPrintTo( BinNo : Integer); var ADevice, ADriver, APort : string; ADeviceMode : THandle; DevMode : PDeviceMode; begin SetLength(ADevice, 255); SetLength(ADriver, 255); SetLength(APort, 255); if ADeviceMode = 0 then begin Printer.PrinterIndex := Printer.PrinterIndex; Printer.GetPrinter(PChar(ADevice), PChar(ADriver), PChar(APort), ADeviceMode); end; if ADeviceMode 0 then begin DevMode := GlobalLock(ADeviceMode); try DevMode^.dmDefaultSource := BinNo; finally GlobalUnlock(ADeviceMode); end; end else raise Exception.Create('Could not set printer copies'); end;