1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55:
| type TBin = record Id: integer; Name: String; end; TBins = array of TBin;
[...]
function TDrucken.getPaperBins(printerId: integer): TBins; type TBinName = array [0..23] of Char; TBinNameArray = array [1..High(Integer) div SizeOf(TBinName)] of TBinName; PBinnameArray = ^TBinNameArray; TBinArray = array [1..High(Integer) div SizeOf(Word)] of Word; PBinArray = ^TBinArray; var Device: array [0..255] of Char; Driver: array [0..255] of Char; Port: array [0..255] of Char; hDevMode: THandle; i: integer; numBinNames: integer; numBins: integer; pBinNames: PBinnameArray; pBins: PBinArray; begin Printer.PrinterIndex := printerId; Printer.GetPrinter(Device, Driver, Port, hDevmode); numBinNames := WinSpool.DeviceCapabilities(Device, Port, DC_BINNAMES, nil, nil); numBins := WinSpool.DeviceCapabilities(Device, Port, DC_BINS, nil, nil); if numBins <> numBinNames then begin raise Exception.Create('DeviceCapabilities reports different number of bins and bin names!'); end; if numBinNames > 0 then begin GetMem(pBinNames, numBinNames * SizeOf(TBinname)); GetMem(pBins, numBins * SizeOf(Word)); try WinSpool.DeviceCapabilities(Device, Port, DC_BINNAMES, PChar(pBinNames), nil); WinSpool.DeviceCapabilities(Device, Port, DC_BINS, PChar(pBins), nil); SetLength(Result, numBinNames - 1); for i := 1 to numBinNames do begin Result[i - 1].Id := pBins^[i]; Result[i - 1].Name := pBinNames^[i]; end; finally FreeMem(pBinNames); if pBins <> nil then FreeMem(pBins); end; end; end; |