Uses Printers;
ComboBox.Items.Assign(Printer.Printers);

解决方案 »

  1.   

    uses
      Printers;// ...procedure TForm1.Button1Click(Sender: TObject);
    begin
      ComboBox1.Items.Assign(Printer.Printers);
    end;
      

  2.   

    Printers是专门用来控制打印机的,可是在没有安装打印机时,却会提示I/O错误,所以必须有一个检测是否存在打印机的方法,我试过很多方法,可是I/O错误总是比我的判断早出现,所以采用以下的烂招来检测打印机。首先在uses增加Printers,再准备一个列表框ComboBox1,其属性Visible设为FALSE,然后在打印之前执行下列语句,那么就可以检测到是否存在打印机了: procedure TForm1.ButtonClick(Sender: Tobject); 
    begin 
    ComboBox1.Clear; 
    ComboBox1.Items.Assign(Printer.Printers); 
    if ComboBox1.Items.CommaText='' then 
    Messagedlg('你需要安装打印机才能打印!',mtError,[mbOk],0); 
    else 
    Form1.Print; 
    end;
      

  3.   

    Uses Printers;ComboBox.Items.Assign(Printer.Printers);