uses
inifiles;
//创建新文件
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 TForm1.Button1Click(Sender: TObject);
var
inifile:TInifile;
iniFileName,sAppPath,sMusicDir,sImageDir:string;
begin
//获取当前程序的路径
sAppPath:=ExtractFilePath(Application.ExeName);
iniFileName:=sAppPath+’testset.ini’;
inifile:=TInifile.Create(iniFileName);
//判断ini文件是否存在(不存在则创建)
if not FileExists(pChar(iniFileName)) then
begin
NewFile(iniFileName,'[TESTSET]’);
//写配置信息
inifile.writeString(‘TESTSET’,’DLGOPENIMGDIR’,sAppPath+’Pictures’);
inifile.writeString(‘TESTSET’,’DLGOPENMICDIR’,sAppPath+’Music’);
end ;
//读取配置信息
sImageDir:=inifile.readString(‘TESTSET’,’DLGOPENIMGDIR’,”);
sMusicDir:=inifile.readString(‘TESTSET’,’DLGOPENMICDIR’,”);
end;