如何有选择地为某些功能包括某些代码? [英] How to optionally include certain code for certain features?

查看:38
本文介绍了如何有选择地为某些功能包括某些代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Inno Setup中,我有一个主脚本,它是核心系统",这意味着安装/运行我们的软件绝对需要的所有东西.另外,我正在为每个主要功能编写脚本文件,这些文件可能会或可能不会编译到安装程序中.在主脚本文件的顶部,我包括其他脚本文件...

In Inno Setup, I have a main script which is the "core system", meaning everything which is absolutely needed for our software to install/run at all. Additionally, I'm writing script files for each major feature which may or may not be compiled into the installer. At the top of the main script file, I include other script files...

#include "AdditionalOption.iss"
#include "AnotherOption.iss"

在编译此主脚本时,编译人员可以选择是否在安装程序中完全编译这些特定选项(出于各种原因来节省文件大小).

When compiling this main script, the person compiling may choose whether or not to compile these certain options in the installer at all (to spare file size for various reasons).

当我在主脚本中有特定的代码取决于这些附加脚本之一中的某些内容时,就会出现问题.例如...

The problem arises when I have specific code in the main script which depends on something in one of these additional scripts. For example...

procedure InitializeWizard();
begin
  //Creates custom wizard page only if "AdditionalOption.iss" is compiled
  CreatePageForAdditionalOption; 
  //Creates custom wizard page only if "AnotherOption.iss" is compiled
  CreatePageForAnotherOption; 
end;

InitializeWizard 只能定义一次,但是我需要根据是否包含其他脚本而有条件地调用其中的代码.这些过程位于相应的脚本文件中,因此,如果用户排除了其他脚本文件,则这些过程当然不存在.

InitializeWizard can only be defined once, but I need to call code in it conditionally depending on whether or not those other scripts were included. Those procedures reside in their appropriate script files, so of course they don't exist if user excluded that other script file.

在Delphi中,我可以像这样使用条件语句:

In Delp I can use conditionals like so:

{$DEFINE ADD_OPT}
{$DEFINE ANO_OPT}

procedure InitializeWizard();
begin
  {$IFDEF ADD_OPT}
  CreatePageForAdditionalOption;
  {$ENDIF}
  {$IFDEF ANO_OPT}
  CreatePageForAnotherOption;
  {$ENDIF}
end;

当然,这实际上不是Delphi.如何在Inno Setup中做这样的事情?

Of course this isn't actually Delphi though. How can I do such a thing in Inno Setup?

推荐答案

Inno Setup具有预处理器,使您可以使用

Inno Setup has a Preprocessor which enables you to make use of #ifdef, #else and #endif which you can set via the iscc.exe /D command line param(s). You can define multiple #ifdef's and set them via multiple /D's.

; Command line param => /DADD_OPT
#ifdef ADD_OPT
  ...
#else
  ...
#endif

我已使用它们覆盖默认值:

I've used them to override default values:

; Command line param => /DENVIRONMENT=Prod
#ifdef ENVIRONMENT
  #define Environment ENVIRONMENT
#else
  #define Environment "Beta"
#endif

这篇关于如何有选择地为某些功能包括某些代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆