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;

These are my three example sections in INNO Setup. I want to use myPascalVar in the INI Section. How can I do it?

Paul R
  • 208,748
  • 37
  • 389
  • 560
user2462794
  • 195
  • 2
  • 6
  • 17
  • If you just want to read the registry, then note that you can use a `{reg:...}` constant instead. Though be aware that reading from HKCU during install may not give you the results you are expecting if you're running as admin. – Miral Nov 05 '13 at 19:40

1 Answers1

12

You will need to change your variable to be in the global scope and write a simple getter function for so called 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;
TLama
  • 75,147
  • 17
  • 214
  • 392