//读配置文件函数
function GetIniData(N1, N2: String): String;
var
strResult, FileName, PN1, PN2
Char;
begin
GetMem(FileName, 100);
Try
GetMem(StrResult, 140);
GetMem(PN1,20);
GetMem(PN2,20);
try
GetPrivateProfileString(StrPCopy(PN1, N1), StrPCopy(PN2,N2),
'', strResult, 140, StrPCopy(FileName, DirString + '/Config.ini'));
Result := StrResult; //读取数据
finally
FreeMem(StrResult);
FreeMem(PN1);
FreeMem(PN2);
end;
finally
FreeMem(FileName);
end;
end;
//写配置文件函数
function WriteIniData(N1, N2, V: String): Bool;
var
FileName, PN1, PN2, PV: PChar;
begin
GetMem(FileName, 100);
Try
GetMem(PN1, 20);
GetMem(PN2, 20);
GetMem(PV, 140);
try
if V = '' then
begin
WritePrivateProfileString(StrPCopy(PN1, N1), // []中标题的名字
StrPCopy(PN2, N2), Nil,
StrPCopy(FileName, DirString + '/Config.ini'))
end
else
WritePrivateProfileString(StrPCopy(PN1, N1), // []中标题的名字
StrPCopy(PN2, N2), // 要写入"="号前的字符串
StrPCopy(PV, V), //要写入的数据
StrPCopy(FileName, DirString + '/Config.ini')); // 调用的文件名
Result := True;
finally
FreeMem(PN1);
FreeMem(PN2);
FreeMem(PV);
end;
finally
FreeMem(FileName);
end;
end;