如何读取 [Setup]
部分中的参数集,即 Pascal 代码中的 Uninstallable
?
我需要知道生成的包是否可卸载的原因是准备页面上显示的信息(Windows 添加/删除显示中的包名称)。如果包是 Uninstallable=no
,则该信息没有意义,所以我不应该在就绪页面上显示它!
非常感谢任何提示!
最佳答案
您可以使用 SetupSetting
preprocessor function在脚本的其他地方发出 Setup
部分指令(Code
或不):
[Setup]
Uninstallable=no
[Code]
...
if '{#SetupSetting('Uninstallable')}' = 'yes' then ...
这导致:
if 'no' = 'yes' then ...
相关问题:How to use Inno Setup preprocessor directive in [Code] section?
虽然我实际上发现您的解决方案更好。但是为了类型安全和避免区分大小写比较或引用值等问题,我会这样做:
#define Uninstallable false
[Setup]
Uninstallable={#Uninstallable ? "yes" : "no"}
[Code]
...
if {#Uninstallable ? 'True' : 'False'} then ...
这会提高效率:
if False then ...
或者实际上,如果您只想跳过整个代码块,请执行以下操作:
[Code]
...
#if Uninstallable
// Do something
#endif
这导致没有代码,当不是“可卸载”时,效率更高并且还减小了安装程序的大小。
然后更常见的是只测试预处理器定义的存在:
//#define Uninstallable
[Setup]
#ifndef Uninstallable
Uninstallable=no
#endif
[Code]
...
#ifdef Uninstallable
// Do something
#endif
关于inno-setup - 如何读取 Pascal 代码中的 [Setup] 参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73672934/