要利用.INI文件做程序有关数据的存储工作,就需要能读和写.INI文件,所以列了如下方法给大家参考:
从.INI文件中获取字符串
var
strResult:pchar;
begin
GetPrivateProfileString(
'windows', // []中标题的名字
'NullPort', // =号前的名字
'NIL', // 如果没有找到字符串时,返回的默认值
strResult, //存放取得字符
100, //取得字符的允许最大长度
'c:\forwin95\win.ini' // 调用的文件名
);
edit1.text:=strResult; //显示取得字符串
从.INI文件中获取整数
edit1.text:=inttostr(GetPrivateProfileInt(
'intl', // []中标题的名字
'iCountry', // =号前的名字
0,// 如果没有找到整数时,返回的默认值
'c:\forwin95\win.ini' // 调用的文件名
));
向.INI文件写入字符串
WritePrivateProfileString(
'windows', // []中标题的名字
'load', // 要写入“=”号前的字符串
'accca', //要写入的数据
'c:\forwin95\win.ini' // 调用的文件名
);
向.INI文件写入整数
WritePrivateProfileSection(
'windows', // []中标题的名字
'read=100', // 要写入的数据
'c:\forwin95\win.ini' // 调用的文件名
);
procedure TMainForm.LoadParameters;
var
TheIni:TIniFile;
begin
TheIni:=TIniFile.Create(Sysdir+'System.Ini');
try
with TheIni do
begin
AutoDelete:=ReadBool('System','AutoDelete',False);
AutoDeleteTime:=ReadInteger('System','AutoDeleteTime',0);
NumberItems:=ReadInteger('System','NumberItems',0);
end;
finally
TheIni.Free;
end;
end;//保存设置参数
Procedure TMainForm.SaveParameters;
var
TheIni:TIniFile;
begin
TheIni:=TIniFile.Create(Sysdir+'System.Ini');
try
with TheIni do
begin
WriteBool('System','AutoDelete',AutoDelete);
WriteInteger('System','AutoDeleteTime',AutoDeleteTime);
WriteInteger('System','NumberItems',NumberItems);
end;
finally
TheIni.Free;
end;
end;
Uses IniFiles;
ini:Tinifile;
name:string;
begin
name := ExtractFilePath(Application.ExeName)+ExtrcatFileExt(ExtractFileName(Application.ExeName),'.ini'); //通过执行文件获得将创建的INI的文件名
ini := TiniCreate(name)
ini.writeString('system','user',user.text);
sysdis := ini.readString('system','sysdir','sys');
....................
多看帮助
实在不好意思!
WritePrivateProfileInt
WritePrivateProfileSection
等等可以写任何文本方式存储的文件,文件后缀可以是.txt、.dat等,但写后文件结构与.ini文件结构类似
GetPrivateProfileString
GetPrivateProfileInt等只能读.ini文件结构的文件,文件后缀可以是.txt、.dat等
详细可见msdn
请问用什么方法能连同指针一起保存到一个文件里{不是指.ini文件},并且下一次初始化时,所有指针都能再次被读出来?然后仍旧能够接着上一次保存的数据继续添加新数据?
说实在的,保存指针有什么用?下次运行就全变了。