Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read a [Setup] parameter in the Pascal code?

Tags:

inno-setup

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!

like image 513
Hannes Schmid Avatar asked Jan 21 '26 20:01

Hannes Schmid


2 Answers

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
like image 196
Martin Prikryl Avatar answered Jan 23 '26 10:01

Martin Prikryl


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?

like image 29
Hannes Schmid Avatar answered Jan 23 '26 10:01

Hannes Schmid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!