InnoSetup:在[代码]部分中获取AppName [英] InnoSetup: Getting AppName in [Code] section

查看:306
本文介绍了InnoSetup:在[代码]部分中获取AppName的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 InnoSetup 创建安装程序,并在部分.在其中一个处理程序中,我希望能够检索在[Setup]部分中定义的AppName的值(或者可能是其他参数的值).我有办法吗?我查看了文档,但是我没有找到任何可以允许我执行此操作的内容.我们的InnoSetup文件实际上是由我们的构建过程生成的,该过程将我们所有程序之间通用且特定于程序的片段拼接在一起,因此为每个程序在代码中定义常量将很不方便.有什么方便的方法吗?

我正在寻找类似的东西

MyString := ExpandConstant('{AppName}');

除了{AppName}不是定义的常数.有什么方法可以查询[Setup]部分中定义的参数?

解决方案

这是一个构建时常量,而不是安装时值.因此,您可以使用 Inno Setup Preprocessor 加载项来定义此类常量. (您可以通过快速入门包轻松安装它.)

定义常量:

#define AppName "Excellent Foo App"

使用[Setup]中的常量:

AppName={#AppName}

在Pascal代码中,我不太确定语法,但是类似:

MyString := {#AppName}

更新:我意识到我的一个脚本使用了{#emit SetupSetting("AppId")},这更容易. Brian的解决方案也发现了这种方法,并且效果更好. /p>

I'm creating an installer using InnoSetup, and writing some custom handlers in a [Code] section. In one of the handlers, I would like to be able to retrieve the value of the AppName (or, potentially, the value of other parameters) defined in the [Setup] section. Is there a way for me to do this? I've looked though the documentation, but I haven't found anything that would allow me to do this. Our InnoSetup files are actually generated by our build process, which stitches together fragments that are common between all of our programs and that are program specific, so it would be inconvenient to have to define constants in the code for each program. Is there any convenient way to do this?

I'm looking for something like

MyString := ExpandConstant('{AppName}');

Except {AppName} is not a defined constant. Is there some way to query for parameters defined in the [Setup] section?

解决方案

It's a build-time constant, not an install-time value. So you can use the Inno Setup Preprocessor add-on to define such constants. (You can install it easily via the QuickStart pack).

Define the constant:

#define AppName "Excellent Foo App"

Use the constant in [Setup]:

AppName={#AppName}

And in Pascal code, I'm not totally sure of the syntax, but something like:

MyString := {#AppName}

Update: I realised one of my scripts uses {#emit SetupSetting("AppId")} which is easier. Brian's solution also discovered this method, and is better.

这篇关于InnoSetup:在[代码]部分中获取AppName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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