uses printers;
var myprinter : integer;
//`枚举打印机列表
var i : integer;
pstr : string;
begin
myprinter := -1;
Memo1.Lines.clear;
for i := 0 to printer.printers.count - 1do
begin
pstr := printer.printers.string;
Memo1.Lines.Add(pstr);//枚举
if pstr = 'MyPrinter' then
myprinter := i;//'MyPrinter'`为控制面板上的打印机名
//设定打印机,初值为-1时为默认打印机
end;
end;
以TQuickRep组件编程调用为例来调用设定的打印机输出:
QuickRep1.PrinterSettings.PrinterIndex := myprinter;
QuickRep1.Print;