3

How can I read a parameter set in the [Setup] section namely Uninstallable in the Pascal code?

The reason why I need to know if the package produced is uninstallable or not, is an information displayed on the ready page (the name of the package in the Add/Remove display of Windows). If the package is Uninstallable=no that information does not make sense so I should no show it on the ready page!

Thanks a lot for any hints!

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Hannes Schmid
  • 379
  • 3
  • 14

2 Answers2

4

You can use SetupSetting preprocessor function to emit the Setup section directive in other places of the script (Code or not):

[Setup]
Uninstallable=no
[Code]
...
if '{#SetupSetting('Uninstallable')}' = 'yes' then ...

This results in:

if 'no' = 'yes' then ...

Related question: How to use Inno Setup preprocessor directive in [Code] section?


Though I actually find your solution better. But for type-safety and avoiding problems like case-sensitive comparison or quoted values, I'd do it like this:

#define Uninstallable false

[Setup]
Uninstallable={#Uninstallable ? "yes" : "no"}
[Code]
...
if {#Uninstallable ? 'True' : 'False'} then ...

This results in more efficient:

if False then ...

Or actually if you just want to skip whole block of code, do:

[Code]
...
#if Uninstallable
// Do something
#endif

This results in no code, when not "uninstallable", what is even more efficient and also reduces the installer size.


And then it is more common to just test for existence of the preprocessor define:

//#define Uninstallable
[Setup]
#ifndef Uninstallable
Uninstallable=no
#endif
[Code]
...
#ifdef Uninstallable
// Do something
#endif
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
1

My 'problem' can be solved as follows:

#define uninstallable "no"
...
[Setup]
...
Uninstallable="{#uninstallable}"
...
[code]
...
if {#uninstallable} = 'yes' then ...

With this uninstallable is known in the pascal code. Not very elegant but possible. I still would like to know if parameters in [Setup] can be read from the pascal code?

Hannes Schmid
  • 379
  • 3
  • 14
  • 1
    This won't compile. Your are missing quotes. It should be `if '{#uninstallable}' = 'yes' then ...`. On the other hand the quotes in `"{#uninstallable}"` are not needed. You typically write `Uninstallable=no`, not `Uninstallable="no"` (although it is possible). – Martin Prikryl Sep 10 '22 at 16:51