TI3329 - Getting All the Bin Names for a Particular Printer
- Product: Delphi
- Version: All
- Platform: Windows/Win32
Q: How do I get all the bin names for a particular printer?
A: This little piece of code demonstrates an easy way to do this.
Just start a brand new project in Delphi. Drop down a TButton
and a TMemo. Then double click on the button and replace the
code in between "{$R *.DFM}" and "end." in Unit1. This will
populate the memo with a list of the binnames.
uses
WinSpool;
const
PName = 'DELPHI III'; {Printer Name}
PPort = '\\CONAN\DELPHI_III'; {UNC Path Name or port, i.e. LPT1}
procedure TForm1.Button1Click(Sender: TObject);
var
i : Integer;
p : PChar;
begin
GetMem(p,24*DeviceCapabilities(PName,PPort,DC_BINNAMES,nil,nil));
with Memo1, Lines do begin
Clear;
for i:=1 to DeviceCapabilities(PName,PPort,DC_BINNAMES,p,nil) do
Add(p+24*(i-1));
end;
FreeMem(p);
end;
Searching in the Win32 Help under DeviceCapabilities brings up a topic
that describes the function in detail. Of particular interest in this
case is the DC_BINNAMES constant. When passed as the third parameter
with a pchar as the fourth parameter the pchar gets pointed to a two
dimensional array of the type listed in the help topic under
DC_BINNAMES.