Inno Setup message parameters

In the Inno Setup help in the 'messages' file I found this:

Some messages accept arguments such as% 1 and% 2. You can change the order of the arguments (i.e., Move% 2 to% 1), and duplicate arguments if necessary (i.e., "% 1 ...% 12" ). In messages with arguments, use two consecutive "%" characters to insert one "%". '% n' creates a line break.

And under "custom posts" it is:

Messages can accept arguments, from% 1 to% 9. You can change the order of the arguments (i.e., Move% 2 to% 1), and duplicate arguments if necessary (i.e., "% 1 ...% 1 % 2 "). In messages with arguments, use two consecutive "%" characters to insert one "%". '% n' creates a line break.

But ... for the life of me I can't figure out how to use them ... so far I've seen% 1 work (translates to app name), but when I change% 1 to% 2 (up to-% 9) it just displays like% 2,% 3,% 4, etc ...

I'm just wondering: How do I use these arguments, where are they assigned?

Greetings,

+3


source to share


1 answer


TL; DR

In the section [Messages]

they are hardcoded and message specific, perhaps not documented. For [CustomMessages]

this you.


1. What are the arguments in the [Messages] section?

In the section, [Messages]

this is difficult to answer as it is hardcoded in the source and is specific to each message, which is a kind of moving target. You can find it if you search for strings FmtSetupMessage

and FmtSetupMessage1

in the original * .pas files. These are where messages are formatted and where they pass their arguments. I don't know if there is any documentation there, so I would stay looking for the source code. Here's a little about search functions.

1.1 FmtSetupMessage function

The first function FmtSetupMessage

can take more than one argument, and its call can be read like this:

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

      

an array (constant) enclosed in parentheses []

represents the arguments in order %1..%n

. If the message msgSomeMessageId

had a translation, let's say:

Lorem %2 ipsum dolor sit %1 amet.

      

then with the above call, the call will be formatted to:

Lorem Argument 2 ipsum dolor sit Argument 1 amet.

      

The meaning of each argument in true Inno Setup source code should be easy to find, but requires at least basic Pascal reading skills.

1.2 FmtSetupMessage1 function

FmtSetupMessage1

easier to read since it only takes one parameter, the argument %1

:



FmtSetupMessage1(msgSomeMessageId, 'Argument')

      

therefore, messages formatted by a function FmtSetupMessage1

most likely only contain an argument %1

.


2. What are the arguments in the [CustomMessages] section?

The section principle [CustomMessages]

provides a way to define custom messages, which includes the arguments you pass to them to format the output string. Thus, it is entirely up to you that you go to any of the following methods.

2.1 The {cm: ...} constant in script sections

In script sections, you can use constants {cm:...}

where you can pass arguments as a comma separated list after the message name. For example:

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

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

      

will result in this formatted message:

Lorem Argument 2 ipsum dolor sit Argument 1 amet.

      

Since the {cm:...}

const format is more complex than this, I would like to ask for help for details.

2.2 FmtMessage function in the [Code] section

In the section, [Code]

you can use a function FmtMessage

to format the message with support for these kind of arguments. To get a custom message you can use the function CustomMessage

. Here's a quick example with the same result as above:

[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;

      

+3


source







All Articles