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: 56: 57:
| type TPaperName = array[0..63] of Char;
procedure GetPapernames(sl: TStrings; index : integer);
uses [...], winspool, Printers;
procedure GetPapernames(sl: TStrings; index: Integer); type TPaperNameArray = array[1..High(Integer) div Sizeof(TPaperName)] of TPaperName; PPapernameArray = ^TPaperNameArray; TPaperArray = array[1..High(Integer) div Sizeof(Word)] of Word; PPaperArray = ^TPaperArray; var Device, Driver, Port: array[0..255] of Char; hDevMode: THandle; i, numPaperNames, numPapers, temp: Integer; pPaperNames: PPapernameArray; pPapers: PPaperArray; begin Assert(Assigned(sl)); Printer.PrinterIndex := index; Printer.GetPrinter(Device, Driver, Port, hDevmode); numPaperNames := WinSpool.DeviceCapabilities(Device, Port, DC_PAPERNAMES, nil, nil); numPapers := WinSpool.DeviceCapabilities(Device, Port, DC_PAPERS, nil, nil); if numPapers <> numPaperNames then begin raise Exception.Create('DeviceCapabilities reports different number of papers and paper-names'); end; if numPaperNames > 0 then begin GetMem(pPaperNames, numPaperNames * Sizeof(TPapername)); GetMem(pPapers, numPapers * Sizeof(Word)); try WinSpool.DeviceCapabilities(Device, Port, DC_PAPERNAMES, Pchar(pPaperNames), nil); WinSpool.DeviceCapabilities(Device, Port, DC_PAPERS, Pchar(pPapers), nil); sl.clear; for i := 1 to numPaperNames do begin temp := pPapers^[i]; sl.addObject(pPaperNames^[i], TObject(temp)); end; finally FreeMem(pPaperNames); if pPapers <> nil then FreeMem(pPapers); end; end; end;
procedure TfrmWizard.ComboBox1Change(Sender: TObject); var ind : integer; begin ind := ComboBox1.ItemIndex; getpapernames(ComboBox2.Items,ind); end; |