Inno Setup从.ini读取值

时间:2012-03-21 10:21:59

标签: inno-setup ini

我想从.ini文件中读取值。然后写一个条件 - 如果这个值等于“1”,那么做某事(执行一个动作)。 我试过 getinistring ,但我没有得到任何值(只显示默认值)。 我不知道如何在我下面的代码中实现 readini 。 谢谢你的帮助, IS初学者:)

//编辑 这是一个代码:

#include ReadReg(HKEY_LOCAL_MACHINE,'Software\Sherlock Software\InnoTools\Downloader','ScriptPath','');
#include ReadReg(HKEY_LOCAL_MACHINE,'Software\Sherlock Software\InnoTools\Tray','ScriptPath','');

[Languages]
Name: english; MessagesFile: compiler:Default.isl

[Code]
function isxdl_Download(hWnd: Integer; URL, Filename: AnsiString): Integer;
external 'isxdl_Download@files:isxdl.dll stdcall';
function isxdl_SetOption(Option, Value: AnsiString): Integer;
external 'isxdl_SetOption@files:isxdl.dll stdcall';
var
a :string;
b :string;

//Downloading a component depending on component choice in another setup(read from .ini)
procedure CurStepChanged(CurStep: TSetupStep);
begin
a:=GetIniString('Select', 'First', 'false', '{pf}/SP_Settings.ini');
b:=GetIniString('Select', 'Should', 'true', {pf}\SP_Settings.ini');

begin
if CompareStr(a,b)=0 then
  if CurStep=ssInstall then begin
      isxdl_SetOption('title', 'File Download');
      isxdl_SetOption('label', 'Download');
      isxdl_SetOption('description', 'Setup is downloading a file.');
      isxdl_Download(0,'url', ExpandConstant('{app}\x.rar'));   
      end;      
end;
end;

[Files]
Source: C:\Documents and Settings\user\Pulpit\XML\Project\isxdl.dll; DestDir: {tmp}; Flags: dontcopy

1 个答案:

答案 0 :(得分:6)

可以使用像GetIniIntGetIniString这样的Pascal脚本函数来读取ini文件。请参阅this reference

我想请注意,在OP改变他的问题之前我写了这个回复,告诉我们他已经尝试了GetIniStringReadIni函数。是的:在写这个答案之前我确实读过这个问题: - )

从您发布的代码中我可以看到您正在尝试从Program Files文件夹中读取ini文件。但是,这仅在使用ExpandConstant函数时有效,因此应该读取

a:=GetIniString('Select', 'First', 'false', ExpandConstant('{pf}') + '\SP_Settings.ini');
b:=GetIniString('Select', 'Should', 'true', ExpandConstant('{pf}') + '\SP_Settings.ini');
相关问题