How to optionally include specific code for certain functions?

In Inno Setup, I have a main script, which is the "main system", which means everything that is absolutely necessary for our software to install / run in general. In addition, I write script files for each main function, 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, face compilation can choose whether to compile these specific parameters in the installer at all (to save file size for various reasons).

The problem occurs when I have special code in the main script that 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 , , . script, , , , script.

Delphi :

{$DEFINE ADD_OPT}
{$DEFINE ANO_OPT}

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

, Delphi. Inno Setup?

+4
2

Inno Setup , #ifdef, #else #endif, iscc.exe /D . #ifdef /D.

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

:

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

, . , ...

{$DEFINE ADD_OPT}
{$DEFINE ANO_OPT}

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

Inno Setup ...

#define Public ADD_OPT
#define Public ANO_OPT

procedure InitializeWizard();
begin
  #ifdef ADD_OPT
  CreatePageForAdditionalOption;
  #endif
  #ifdef ANO_OPT
  CreatePageForAnotherOption;
  #endif
end;
+1

Source: https://habr.com/ru/post/1525116/


All Articles