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