[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 中的三个示例部分。我想在 INI 部分使用 myPascalVar。我该怎么做?

最佳答案

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

[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;

关于windows - 如何在 Inno Setup 中使用 Pascal 变量?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19757284/

10-15 23:41