var Printer_List: TStringList; begin Printer.Refresh; Printer_List := TStringList.Create; Printer_List.Clear; Printer_List.Assign(Printer.Printers); if Printer_List.CommaText = '' then begin Application.MessageBox('打印机未安装!', '警告提示', mb_Ok + mb_iconWarning); application.Terminate; end; end;
var ADevice,ADriver,APort:Array[0..255] of Char; DeviceHandle:THandle; begin Printer.GetPrinter(ADevice,ADriver,APort,DeviceHandle); if DeviceHandle=0 then //句柄是0 ,表示打印机没有装载 begin Printer.PrinterIndex:=Printer.PrinterIndex; Printer.GetPrinter(ADevice,ADriver,APort,DeviceHandle); end; if DeviceHandle=0 then Application.MessageBox('默认打印机不存在,请检查打印机设置!', '系统信息',Mb_ok);end;
...
Printer_List: TStringList;
begin
Printer.Refresh;
Printer_List := TStringList.Create;
Printer_List.Clear;
Printer_List.Assign(Printer.Printers);
if Printer_List.CommaText = '' then
begin
Application.MessageBox('打印机未安装!', '警告提示', mb_Ok + mb_iconWarning);
application.Terminate;
end;
end;
ADevice,ADriver,APort:Array[0..255] of Char;
DeviceHandle:THandle;
begin
Printer.GetPrinter(ADevice,ADriver,APort,DeviceHandle); if DeviceHandle=0 then //句柄是0 ,表示打印机没有装载
begin
Printer.PrinterIndex:=Printer.PrinterIndex;
Printer.GetPrinter(ADevice,ADriver,APort,DeviceHandle);
end; if DeviceHandle=0 then
Application.MessageBox('默认打印机不存在,请检查打印机设置!',
'系统信息',Mb_ok);end;
Printer;
try
Printer.Handle;
except
ShowMessage("没有安装打印机.");
end;