本文以實例說明Delphi列印程式的實作方法。此實例可以偵測系統中安裝的所有印表機,列舉這些印表機,主要功能代碼非常簡單,方便大家閱讀與理解。
主要功能代碼如下:
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,Printers, XPMan;type TForm1 = class(TForm) Button1: TButton; Group1: TGroupBox TG1: TButton; ; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Senderlementation{$R *.dfm}procedure TForm1.Button1Click(Sender: T1); ; memo1.Lines.Assign(Printer.Printers); if trim(memo1.Text) = '' then begin showmessage('沒有安裝印表機!'); end;end;procedure TForm1.Button2Click(Sender: TObject);begin Close;end;end.