需要引用单元 inifiles , Forms
1、判断文件是否存在、存在即写入、不存在即创建
var
Tempfile:Textfile;
FileHandle:Thandle;
if fileexists(extractfilepath(application.exename)+'log.log') then
begin
assignfile(tempfile,extractfilepath(application.exename)+'log.log');
APPEND(TEMPFILE);
Writeln(TEMPFILE,datetimetostr(now)+'--'+'写入测试');
CLOSEFILE(TEMPFILE);
end
else
begin
FileHandle := FileCreate(extractfilepath(application.exename)+'log.log');
FileClose(FileHandle);
end;
2、INI配置文件使用
读取ini文件:
with Tinifile.Create(extractfilepath(application.exename)+'SystemSet.INI') do
begin
//配置参数
Hport:=strtoint(ReadString('SYS','port',''));
Fpath:=ReadString('SYS','path','');
Free;
end;
写入ini文件:
with Tinifile.Create(extractfilepath(application.ExeName)+'SystemSet.ini') do
begin
WriteString('Sys','port','8080');
end;