4
[Files]
Source: "C:\MyProg.exe"; DestDir: "{app}"; BeforeInstall: GetHome(); Flags: ignoreversion
[INI]
Filename: "{myVarFromPascal}\.MyProg\settings.ini"; Section: "Settings"; Key: "sound"; String: "1"; Flags: createkeyifdoesntexist
[Code]
procedure GetHome();
     var
  myPascalVar: String;
begin
   RegQueryStringValue(HKEY_CURRENT_USER, 'Volatile Environment','USERPROFILE', myPascalVar);
   MsgBox('Value is "' + myPascalVar + '"', mbInformation, MB_OK);
end;

这是我在 INNO Setup 中的三个示例部分。我想myPascalVar在 INI 部分中使用。我该怎么做?

4

1 回答 1

11

您需要将变量更改为全局范围,并为所谓的编写一个简单的 getter 函数scripted constant

[Files]
Source: "C:\MyProg.exe"; DestDir: "{app}"; BeforeInstall: GetHome; Flags: ignoreversion

[INI]
Filename: "{code:GetMyVar}\.MyProg\settings.ini"; Section: "Settings"; Key: "sound"; String: "1"; Flags: createkeyifdoesntexist

[Code]
var
  myPascalVar: string;

function GetMyVar(Value: string): string;
begin
  Result := myPascalVar;
end;

procedure GetHome;
begin
  RegQueryStringValue(HKEY_CURRENT_USER, 'Volatile Environment', 'USERPROFILE', myPascalVar);
  MsgBox('Value is "' + myPascalVar + '"', mbInformation, MB_OK);
end;
于 2013-11-03T19:58:04.850 回答