Pregunta

How can I use values from the [Setup] section in code?

I suspect I'm using the tool incorrectly; maybe I should be doing this in a different way entirely.

[Setup]
MyValue=some value

[code]

function InitializeSetup(): Boolean;
begin
  // blank
  MsgBox(GetEnv('MyValue'), mbError, MB_OK);

  // no expansion occurs
  MsgBox(ExpandConstant('MyValue'), mbError, MB_OK);

  // unknown constant "MyValue".
  MsgBox(ExpandConstant('{MyValue}'), mbError, MB_OK);

  Result := true;
end;

thank you for your help!

¿Fue útil?

Solución

You cannot declare variable in the [Setup] section. This section may contain only a set of predefined directives. If your aim was to define a constant which could be used in script section entries as well as in script coding [Code] section, then you were looking for preprocessor variables declared by #define directive. For example:

#define MyValue "some value"

[Setup]
AppName={#MyValue}
AppVersion=1.5
DefaultDirName={pf}\My Program

[INI]
Filename: "MyProg.ini"; Section: "InstallSettings"; Key: "InstallPath"; String: "{#MyValue}"

[Code]
function InitializeSetup: Boolean;
begin
  Result := True;
  MsgBox('{#MyValue}', mbInformation, MB_OK);
end;

What actually happens behind a {#MyValue} statement is that the preprocessor emits the value of the defined MyValue constant to the final script.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top