views:

483

answers:

2

I'm creating an installer using InnoSetup, and writing some custom handlers in a [Code] section. In one of the handlers, I would like to be able to retrieve the value of the AppName (or, potentially, the value of other parameters) defined in the [Setup] section. Is there a way for me to do this? I've looked though the documentation, but I haven't found anything that would allow me to do this. Our InnoSetup files are actually generated by our build process, which stitches together fragments that are common between all of our programs and that are program specific, so it would be inconvenient to have to define constants in the code for each program. Is there any convenient way to do this?

I'm looking for something like

MyString := ExpandConstant('{AppName}');

Except {AppName} is not a defined constant. Is there some way to query for parameters defined in the [Setup] section?

+5  A: 

It's a build-time constant, not an install-time value. So you can use the Inno Setup Preprocessor add-on to define such constants. (You can install it easily via the QuickStart pack).

Define the constant:

#define AppName "Excellent Foo App"

Use the constant in [Setup]:

AppName={#AppName}

And in Pascal code, I'm not totally sure of the syntax, but something like:

MyString := {#AppName}

Update: I realised one of my scripts uses {#emit SetupSetting("AppId")} which is easier. Brian's solution also discovered this method, and is better.

Craig McQueen
Hmm. I'd prefer not to have to define every AppName as a macro, and then use that macro to define the real AppName in every program. But this is a start.
Brian Campbell
I know what you mean. But I'm not aware of any other way to do it.
Craig McQueen
+3  A: 

Inspired by Craig's answer, I was looking at the Inno Setup Preprocessor documentation (in ISTool, not available online as far as I've found), and came across the SetupSetting function in the preprocessor.

It can be used as so:

MyString := '{#SetupSetting("AppName")}';

And as long as the [Setup] section appears before the place where this is used (ISPP seems to be only one pass), and includes a definition for AppName, this will give the results I want, without having to define an extra macro for each setting we want to extract.

Brian Campbell
I was just looking over one of my scripts, and discovered I'd used this (actually I had used `{#emit SetupSetting("AppId")}` but close enough). I came to update my answer, but I see you've beaten me to it!
Craig McQueen
{# is shorthand for {#emit
mlaan