unit zs_dyjpz;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls,Printers,WinSpool,IniFiles;
type
TW_dyjpz = class(TForm)
pnl1: TPanel;
lbl1: TLabel;
cbb1: TComboBox;
lbl2: TLabel;
cbb2: TComboBox;
btn1: TButton;
btn2: TButton;
procedure btn2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
W_dyjpz: TW_dyjpz;
implementation
{$R *.dfm}
procedure TW_dyjpz.btn2Click(Sender: TObject);
begin
Self.Close;
end;
procedure TW_dyjpz.FormShow(Sender: TObject);//下拉列表显示打印机
begin
cbb1.Items.Assign(Printer.Printers);
cbb1.ItemIndex := 0;
cbb2.Items.Assign(Printer.Printers);
cbb2.ItemIndex := 0;
end;
//创建新文件
Procedure NewFile(FileName:String;Text:String);
Var
F : Textfile;
Begin
if fileExists(FileName) then DeleteFile(FileName); {看文件是否存在,在就刪除}
AssignFile(F, FileName); {将文件名与变量 F 关联}
ReWrite(F); {创建一个新的文件并命名为 ek.txt}
Writeln(F,Text);
Closefile(F); {关闭文件 F}
End;
procedure TW_dyjpz.btn1Click(Sender: TObject);
var
inifile:TInifile;
iniFileName,sAppPath,sMusicDir,sImageDir:string;
begin
//获取当前程序的路径
sAppPath:=ExtractFilePath(Application.ExeName);
iniFileName:=sAppPath+'printerPZ.ini';
inifile:=TInifile.Create(iniFileName);
//判断ini文件是否存在(不存在则创建)
if not FileExists(pChar(iniFileName)) then
begin
NewFile(iniFileName,'[printerPZ]');
//写配置信息
inifile.writeString('printerPZ','bddyjpz',cbb1.Text);
inifile.writeString('printerPZ','tzsdyjpz',cbb2.Text);
end ;
messagebox(handle,'设定成功!','提示信息',MB_OK);
end;
end.
参考网址:https://blog.csdn.net/jean852001/article/details/43760591
delphi中使用配置文件 *.ini
最新推荐文章于 2022-03-24 16:17:46 发布