Inno Setup 消息参数

Inno Setup Message Arguments

在 'messages' 文件下的 Inno Setup 帮助中,我发现了这个:

Some messages take arguments such as %1 and %2. You can rearrange the order of the arguments (i.e. move the %2 before a %1) and also duplicate arguments if needed (i.e. "%1 ... %1 %2"). On messages with arguments, use two consecutive "%" characters to embed a single "%". "%n" creates a line break.

在 'custom messages' 下面:

Messages may take arguments, from %1 up to %9. You can rearrange the order of the arguments (i.e. move the %2 before a %1) and also duplicate arguments if needed (i.e. "%1 ... %1 %2"). On messages with arguments, use two consecutive "%" characters to embed a single "%". "%n" creates a line break.

但是...我一辈子都不知道如何使用这些...到目前为止我已经看到 %1 有效(转换为应用程序名称)但是当我将 %1 更改为 %2 (最多 %9)它只是显示为 %2、%3、%4 等等....

我很好奇 - 我如何使用这些参数,它们分配在哪里?

干杯,

tl;博士

对于 [Messages] 部分,它们是硬编码的并且是特定于消息的,可能没有记录。 [CustomMessages] 就交给你了。


1。 [消息] 部分中的参数是什么?

对于 [Messages] 部分,这很难回答,因为它在源代码中是硬编码的,并且特定于每条消息,因此它是一种移动目标。如果您在源 *.pas 文件中搜索 FmtSetupMessageFmtSetupMessage1 字符串,就可以找到它们。这些是格式化消息和传递参数的地方。我不知道是否有这方面的文档,所以我会继续搜索源代码。这里有一些关于要搜索的函数的信息。

1.1 FmtSetupMessage函数

第一个函数FmtSetupMessage可以接受多个参数,它的调用可以这样读:

FmtSetupMessage(msgSomeMessageId, ['Argument 1', 'Argument 2'])

[] 括号中的(逗号分隔)常量数组是顺序为 %1..%n 的参数。如果 msgSomeMessageId 消息有翻译,请说:

Lorem %2 ipsum dolor sit %1 amet.

然后上面的示例调用将被格式化为:

Lorem Argument 2 ipsum dolor sit Argument 1 amet.

真正的 Inno Setup 源代码中每个参数的含义应该很容易找到,但至少需要基本的 Pascal 语言阅读能力。

1.2 FmtSetupMessage1函数

FmtSetupMessage1 更容易阅读,因为它只有一个参数,即 %1 参数:

FmtSetupMessage1(msgSomeMessageId, 'Argument')

因此,由 FmtSetupMessage1 函数格式化的消息很可能只包含 %1 参数。


2。 [CustomMessages] 部分中的参数是什么?

[CustomMessages] 部分的原理是提供一种定义自定义消息的方法,其中包括您传递给它们以格式化输出字符串的参数。因此,您将通过以下任何一种方式传递什么完全取决于您。

2.1 脚本部分中的 {cm:...} 常量

在脚本部分,您可以使用 {cm:...} 常量,您可以在其中将参数作为消息名称后的逗号分隔列表传递。例如:

[CustomMessages]
MyMessage=Lorem %2 ipsum dolor sit %1 amet.

[Run]
;                                              ↓ Name    ↓ %1       ↓ %2
Filename: "{app}\MyApp.exe"; Description: "{cm:MyMessage,Argument 1,Argument 2}"

将生成此格式的消息:

Lorem Argument 2 ipsum dolor sit Argument 1 amet.

由于{cm:...}常量格式比这更复杂,我会请你帮忙了解详情。

2.2 [代码]部分的FmtMessage函数

[Code] 部分您可以使用 FmtMessage function to format the message with this sort of argument support. To get the custom message you can use the CustomMessage 函数。这是一个与上述结果相同的简短示例:

[CustomMessages]
MyMessage=Lorem %2 ipsum dolor sit %1 amet.

[Code]
procedure InitializeWizard;
var
  S: string;
begin
  //                             ↓ Name         ↓ %1          ↓ %2
  S := FmtMessage(CustomMessage('MyMessage'), ['Argument 1', 'Argument 2']);
  MsgBox(S, mbInformation, MB_OK);
end;