如题!

解决方案 »

  1.   

    HKEY_LOCAL_MACHINE\Config\0001\System\CurrentControlSet\Control\Print\Printers
    下的default的值是否为空
      

  2.   

    var
      Device:array[0..cchDeviceName-1]of char;
      Driver:array[0..MAX_PATH-1] of char;
      port:array[0..32] of char;
      hDMode:THandle;
    begin
       printer.GetPrinter(Device,Driver,port,hDMode);
       if printer.PrinterIndex=0 then
        Messagedlg('你需要安装打印机才能打印!',mtError,[mbOk],0);
      

  3.   

    if  printer.Printers.Count = 0 then 
        Messagedlg('你需要安装打印机才能打印!',mtError,[mbOk],0);
      

  4.   

    转贴
    function TFBillPreview.CheckPrinterConnect: Boolean;
      function GetCurrentPrinterHandle: THandle;
      var
        Device, Driver, Port : array[0..215] of char;
        hDeviceMode: THandle;
      begin
        Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
        OpenPrinter(@Device, Result, nil);
      end;
    type
      TJobs = Array [0..1000] of JOB_INFO_1;
      PJobs = ^TJobs;
    var
      hPrinter : THandle;
      bytesNeeded, numJobs: Cardinal;
      pJ: PJobs;
    begin
      CheckPrinterConnect := False;
      hPrinter:= GetCurrentPrinterHandle;
      try
        EnumJobs( hPrinter, 0, 1000, 1, nil, 0, bytesNeeded, numJobs );
        pJ := AllocMem( bytesNeeded );
        If EnumJobs( hPrinter, 0, 1000, 1, pJ, bytesNeeded, bytesNeeded, numJobs ) then
          CheckPrinterConnect := True;
      finally
        ClosePrinter( hPrinter );
      end;
    end;
      

  5.   

    kaiyun97(黑马不黑)的方法简洁明快!看TPrinter的定义:TPrinter = class(TObject)
    private
      ...
      function GetPrinters: TStrings;
      ...
    public
      property Printers: TStrings read GetPrinters;
      ...
    end; hongqi162(失踪的月亮)的答案冗长且printer.PrinterIndex=0 会得出错误的结论