Why preprocessor behaves differently in #include directive then in [Files] section Inno Setup script

爱⌒轻易说出口 提交于 2019-12-01 11:34:00

问题


Was trying to understand the difference between a syntax that would include another script file and a source file in Inno Setup script while using macros to search and find files.

I have tried to use FindFolder function from Find a directory using wildcard in Inno Setup:

#define FindFolder(Path) \
    Local[0] = FindFirst(Path, faDirectory), \
    Local[0] ? AddBackslash(ExtractFileDir(Path)) + FindGetFileName(Local[0]) : Path

Like this:

#include "{#FindFolder('..\..\..\packages\ScriptPreRequisites*')}\DotNetDependencies.iss"

回答1:


Within # you are in the "realm" of Inno Setup preprocessor.

There are two ways to enter preprocessor realm.

  • Full line syntax:

    #directive args
    
  • And inline syntax:

    {#directive args}
    

    The inline syntax is almost exclusively used for emit directive - {#emit <expression>}. And for this reason there's a shorthand format, with the emit omitted: {#<expression>}.

The inline syntax is useful when you want to use preprocessor expression outside of preprocessor realm. Like in normal Inno Setup sections (or in Pascal Script code):

[Files]
Source: "{#FindFolder("..\packages\PackagesA*")}\*.*"; DestDir: "{app}"; \
    flags: recursesubdirs  

Though in #include preprocessor directive, you are already in the preprocessor realm. And there, the {#xxx} syntax is invalid (it might even have a different [valid] meaning theoretically, but actually curly brackets have no use in preprocessor).

The syntax of #include directive is:

#include <expression>

The preprocessor uses C-like expression syntax. So your expression in this case is:

FindFolder('..\..\..\packages\ScriptPreRequisites*') + '\DotNetDependencies.iss'


来源:https://stackoverflow.com/questions/53779355/why-preprocessor-behaves-differently-in-include-directive-then-in-files-secti

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!