ini文件中的内容多次读入时为什么会出错。是溢出了吗?(50分)

  • 主题发起人 主题发起人 yuanlaqin
  • 开始时间 开始时间
Y

yuanlaqin

Unregistered / Unconfirmed
GUEST, unregistred user!
我想保存一个软件中的相关设置内容到一个ini文件中,可是启动程序多次读入该内容时总是提示
出错,怎么解决啊?
在线等待
 
把代码贴上来看看
 
我同事也碰到过这问题,也没有解决
 
就是下面的代码,只不过握把读的语句调用了多次的时候就出错了。
//向.INI文件写入字符串
WritePrivateProfileString(
'testfile', // []中标题的名字
'btn4', // 要写入“=”号前的字符串
'黄淮海ggggg', //要写入的数据
'd:/Program Files/Borland/Delphi5/Projects/testfile.ini' // 调用的文件名
);
//向.INI文件写入整数
WritePrivateProfileSection(
'windows', // []中标题的名字
'read=100', // 要写入的数据
'c:/forwin95/win.ini' // 调用的文件名
);

var
strResult:PChar;
begin
strResult:='';//初始化很重要,否则会出错的
GetPrivateProfileString(
'testfile', // []中标题的名字
'btn1', // =号前的名字
'NIL', // 如果没有找到字符串时,返回的默认值
strResult, //存放取得字符
200, //取得字符的允许最大长度
'D:/Program Files/Borland/Delphi5/Projects/testfile.ini' // 调用的文件名
);
edit1.text:=strResult; //显示取得字符串
//从.INI文件中获取整数
//edit1.text:=inttostr(GetPrivateProfileInt(
//'testfile', // []中标题的名字
//'btn4', // =号前的名字
//0,// 如果没有找到整数时,返回的默认值
//'d:/Program Files/Borland/Delphi5/Projects/testfile.ini' // 调用的文件名
//));
end;
 
不明白为什么要写这么复杂,为什么不用TInifile呢?
 
我也碰到过这个问题,奇怪的时候过了几天问题自然消除了,
可能是系统的问题把。
 
麻烦说说怎么用Tinifile?
 
看帮助啊!别告诉我你不会用帮助啊!我要晕的!
 
uses inifiles;

procedure xxx;
var
test: tinifile;
a: String;
begin
test := tinifile.create('c:/xxx.ini');
with test do begin
a := readstring('windows','read','100') //读
b:= writestring('windows','read',yourvalue); //写
end;
test.free;
end;
 
uses
inifiles;

var
fIni:TInifile;
fIni:=TIniFile.Create('c:/temp.ini');
try
fIni.WriteString('接点名称','数据名称','数据');
str:=fIni.readString('接点名称','数据名称','');

finally
fIni.Free;
end;
 
多人接受答案了。
 
后退
顶部