如何在Inno Setup中使用Pascalvariables?

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

Solutions Collecting From Web of "如何在Inno Setup中使用Pascalvariables?"

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