delphi代码解析fileexists('.\setup.ini')

来源:百度知道 编辑:UC知道 时间:2024/06/08 11:30:15
fileexists('.\setup.ini')和
fileexists(extractfilepath(paramstr(0)+'setup.ini'))

作用分别是什么,区别在哪里?
procedure TForm1.FormCreate(Sender: TObject);
begin
datetimepicker1.Time:=now;
if fileexists('.\setup.ini') then //判断当前路径下是否存在setup.ini文件,若存在则执行。
begin
inifile:=Tinifile.Create('.\setup.ini');
if inifile.ReadBool('是否开机自启动','设置',True) then
begin
checkbox1.Checked:=true;
end;
if TimeToStr(inifile.ReadTime('关机提示时间','提示时间',Time))<>'' then
begin
Edit1.Text:=TimeToStr(inifile.ReadTime('关机提示时间','提示时间',Time));
CheckBox3.Checked:=True;
end;
button2.Click;
end;

end;

为什么我使用fileexists(extractfilepath(paramstr(0)+'setup.ini')) 后面的代码不能执行,使用fileexi

应该先用:

chdir(getcurrentdir);

设置程序所在目录为默认目录,后面就不需要设置和检测目录了。
或者类似用:
Create(getcurrentdir+'\setup.ini');

extractfilepath(paramstr(0) 这个是决对的路径。。当你是C:/www/里面
就会自动读C:/www/setup.ini
第一个也行的。不过对一些电脑有可能是找不到路径时会打不开文件的。。

paramstr(0) 返回当前可执行文件完整的文件名
extractfilepath() 返回指定文件名的路径名
fileexists() 判断指定文件是否存在

检查文件是否存在 如存在返回true 不存在返回false
extractfilepath 取一个文件路径的目录部分 不包括/
paramstr(0) 取当前程序运行路径