我有一段程序,是读取System.ini文件的内容,这个文件是自己创建的。
System.ini内容如下
[bmp]
count=5我在Delphi中写了如下语句
use IniFiles;var
Ini:TIniFile;
Count:integer;
begin
Ini:=TiniFile.Create("System.ini");
Count:=Ini.ReadInteger('bmp','count',0);
...
end;但是每次读取时变量Count的值是都是0,而不是5,这是什么原因?
System.ini内容如下
[bmp]
count=5我在Delphi中写了如下语句
use IniFiles;var
Ini:TIniFile;
Count:integer;
begin
Ini:=TiniFile.Create("System.ini");
Count:=Ini.ReadInteger('bmp','count',0);
...
end;但是每次读取时变量Count的值是都是0,而不是5,这是什么原因?
'System.ini'加上路文件名全称(包括路径)
lsConList:TstringList;
Count,Count2:string;
begin
lsConList:=TstringList.Create;
if FileExists('system.ini') then
lsConList.LoadFromFile('system.ini');
Count :=lsConList.Strings[1];
Count2 :=lsConList.Strings[2];
...
end;
'System.ini'加上路文件名全称(包括路径)
Ini:=TiniFile.Create("System.ini");
第二,ReadInteger这个方法,大家都已很清楚,第一个参数是Section,就是方括号括起来的那一部分,第二个参数是Ident,就是等号左边的那一部分,第三个参数是缺省值,就是说如果这个冬冬没有找到(在INI文件里没有)就返回什么值。
Count:=Ini.ReadInteger('bmp','count',0);
这很简单,System.ini里没有这样的冬冬:[bmp]
count=5所以它返回的值就是0,不可能是其他,呵呵。
楼主是“逗您玩儿”吧?
ReadInteger函数中的最后一个参数是默认值,如果ini文件中没有bmp或count的话,那么,默认的返回值就是0。所以……呵呵不用多说了吧。