给你一个设置打印机的函数:
function SetCurPrinter(sIndex: string): Boolean;
var
Device: array[0..255] of Char;
Driver: array[0..255] of char;
Port: array[0..255] of char;
s : array[0..255] of Char;
hDeviceMode: THandle;
I: Integer;
begin
for I := 0 to Printer.Printers.Count - 1do
if Printer.Printers.Strings = sIndex then
begin
Printer.PrinterIndex := I;
Break;
end;
Printer.GetPrinter (Device, Driver, Port, hDeviceMode);
StrCopy (s, Device);
StrCat (s, ',');
StrCat (s, Driver);
StrCat (s, ',');
StrCat (s, Port);
WriteProfileString ('windows', 'device', s);
StrCopy (s, 'windows');
SendMessage (HWND_BROADCAST, WM_WININICHANGE, 0, LongInt(@s));
end;
例如,两台打印机名称为A和B,其端口分别为Port1和Port2,然后:
SetCurPrinter('A on Port1:');
Printer.Print;//打印一部分内容
SetCurPrinter('B on Port2:');
Printer.Print;//打印另一部分内容