Autor Beitrag
motion
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 295

XP, Linux
D7 Prof
BeitragVerfasst: Mo 26.12.05 15:23 
Wie lassen sich für den aktuellen Drucker bzw. einen aus
printer.printers[x] die dort möglichen Papierfächer/Papierquellen auslesen (als Klartext z.b. in eine Stringliste bringen) bzw. setzen?

Gibt es dafür eine empfehlenswerte Komponente/Unit, welche das etwas kapselt und bequem nutzbar macht?
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Fr 30.12.05 00:26 
Hallo,

kA, wo der Code herkommt:

:!: in uses Printers und WinSpool einbinden

ausblenden volle Höhe Delphi-Quelltext
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:
procedure GetBinnames(aStringList: TStrings);
type
  TBinName = array [0..23of Char;
  TBinNameArray = array [1..99of TBinName;
  PBinnameArray = ^TBinNameArray;
  TBinArray = array [1..99of Word;
  PBinArray = ^TBinArray;
var
  szDevice, szDriver, szPort : array[0..255of Char;
  hDevMode                   : THandle;
  i, iBinNames, iBins        : Integer;
  pBinNames                  : PBinnameArray;
  pBins                      : PBinArray;
begin
  Printer.PrinterIndex := -1;
  Printer.GetPrinter(szDevice, szDriver, szPort, hDevmode);
  iBinNames := DeviceCapabilities(szDevice, szPort, DC_BINNAMES, nilnil);
  if iBinNames > 0 then
  begin
    pBins := nil;
    GetMem(pBinNames, iBinNames * Sizeof(TBinname));
    GetMem(pBins, iBins * Sizeof(Word));
    try
      DeviceCapabilities(szDevice, szPort, DC_BINNAMES, PChar(pBinNames), nil);
      DeviceCapabilities(szDevice, szPort, DC_BINS, PChar(pBins), nil);
      aStringList.Clear;
      for i:= 1 to iBinNames do
        aStringList.Add(Format('%s (%d)',[pBinNames^[i], pBins^[i]]));
    finally
      FreeMem(pBinNames );
      if pBins <> nil then
        FreeMem(pBins);
    end;
  end;
end;

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
motion Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 295

XP, Linux
D7 Prof
BeitragVerfasst: So 08.01.06 01:31 
@Lannes,
danke für den Code.
Bin eben erst dazu gekommen den mal zu testen.
Aber das fehlt doch irgend etwas: Die Variable "ibins" wird nicht belegt und trotzdem in einer Berechnung verwendet. Das bemäkelt der compiler zurecht.
Oder habe ich das was nicht begriffen?
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: So 08.01.06 15:28 
Hallo,

hab die Quelle des Codes wieder gefunden,
dort auch setzen der Papierquelle/Papierfach:
Der Entwickler: Druckausgabe auf verschiede Schächte (Delphi5)

Hier im Forum gibt es auch noch das zum gleichen Thema:
Unter Delphi 5 läufts, unter Delphi 7 Fehler - warum?!?

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
motion Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 295

XP, Linux
D7 Prof
BeitragVerfasst: Mo 09.01.06 01:40 
Danke, da stand auch die Lösung.
Die Zeile muss lauten:
GetMem(pBins, iBinNames * Sizeof(Word));


Die Routine funktioniert einwandfrei. Vielen Dank für den Tip.