咨询TIniFile.Create和FileExists问题
我的目的,第一次加载窗体时,将Top的值保存到c:\windows\ying_20110521.ini里,以后加载窗体则从ying_20110521.ini读取Top的值并显示在label1上。可是,按我下面的写法,程序总不会走到label1.Caption:=inttostr(IniFile.ReadInteger('Form','Top',self.Top));我看了程序的执行情况,发现ying_20110521.ini已经生成在c:\windows里了,因此,应该是if not FileExists('ying_20110521.ini') then有问题。
请问,怎么修改下面语句能够达到这样的目的:即判断TIniFile.Create('ying_20110521.ini')语句生成的文件是否已经存在(不要在语句里直接写c:\windows\ying_20110521.ini这样绝对的方式,因为,我怕有的机子把操作系统不是安装在c盘)
procedure TForm1.FormCreate(Sender: TObject);
var
IniFile: TIniFile;
begin
IniFile:=TIniFile.Create('ying_20110521.ini');
try
if not FileExists('ying_20110521.ini') then
begin
IniFile.WriteInteger('Form','Top',self.Top);
end
else
begin
label1.Caption:=inttostr(IniFile.ReadInteger('Form','Top',self.Top));
end;
finally
IniFile.Free;
end;
end;
[解决办法]
写配置文件到windows目录,感觉有点霸道了
我一般是写到exe所在的目录,或者运行时的运行目录(快捷方式的"起始位置")
按微软的要求,最好还是写到用户帐号下的数据目录(个人不喜欢这样,因为配置信息和程序分开的很远了)
[解决办法]
[解决办法]
delphi获取系统特定文件夹路径