ini文件有它的读写规则,这里有我平时用的几个函数你看一看有没有用:
//删除Ini文件中的值
Procedure TFrm_Main.Del_IniFilekey(Section, Ident: string);
var
IniFile: TIniFile;
IniFilePath:string;
begin
IniFilePath := GetAppDir + 'FilesPath.ini';
IniFile:= TIniFile.Create(IniFilePath);
if Not FileExists(IniFilePath) then
IniFile.WriteString('Files_Count','Count','0');
try
IniFile.DeleteKey(Section, Ident);
finally
IniFile.Free;
end;
end;
//写入Ini文件
Procedure TFrm_Main.WriteIniFile(Section, Ident,StringName: string);
var
IniFile: TIniFile;
IniFilePath:string;
begin
IniFilePath := GetAppDir + 'FilesPath.ini';
IniFile:= TIniFile.Create(IniFilePath);
if Not FileExists(IniFilePath) then
IniFile.WriteString('Files_Count','Count','0');
try
IniFile.WriteString(Section, Ident,StringName);
finally
IniFile.Free;
end;
end;
//读取Ini文件
function TFrm_Main.ReadIniFile(Section, Ident: string): string;
var
IniFile: TIniFile;
IniFilePath:string;
begin
IniFilePath := GetAppDir + 'FilesPath.ini';
IniFile:= TIniFile.Create(IniFilePath);
if Not FileExists(IniFilePath) then
IniFile.WriteString('Files_Count','Count','0');
try
Result:=IniFile.ReadString(Section, Ident,'');
finally
IniFile.Free;
end;
end;