如何在Inno Setup中使用Pascal变量?

时间:2013-11-03 19:50:05

标签: windows inno-setup pascal

[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。我该怎么办?

1 个答案:

答案 0 :(得分:10)

您需要将变量更改为全局范围,并为所谓的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;