Reputation: 3294
In the Inno Setup help under 'messages' file I found this:
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.
And under 'custom messages' this:
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.
But... for the life of me I can't find out how to use these... so far I have seen %1 work (translates to app name) but when I change %1 to %2 (up to-%9) it simply displays as %2, %3, %4 and so on....
I'm just curious - how do I use these arguments, where are they assigned?
Cheers,
Upvotes: 6
Views: 2628
Reputation: 76683
For the [Messages]
section they are hardcoded and message specific, probably not documented. For the [CustomMessages]
it's upon you.
For the [Messages]
section this is difficult to answer as it is hardcoded in the source, and specific for each message so it's a sort of a moving target. You can find them if you'll search for FmtSetupMessage
and FmtSetupMessage1
string in the source *.pas files. These are the places where the messages are formatted and where they get passed their arguments. I don't know if there's a documentation for this, so I would stay by searching the source code. Here is a bit about the functions to search for.
The first function FmtSetupMessage
can take more than one argument and its call can be read like this:
FmtSetupMessage(msgSomeMessageId, ['Argument 1', 'Argument 2'])
the (comma separated) array of constants enclosed by the []
brackets are the arguments in the order %1..%n
. If the msgSomeMessageId
message were having a translation, say:
Lorem %2 ipsum dolor sit %1 amet.
then with the above example call would get formatted into:
Lorem Argument 2 ipsum dolor sit Argument 1 amet.
The meaning of each argument in real Inno Setup source code should be easy to find but requires at least basic reading skills of Pascal language.
The FmtSetupMessage1
is easier to read, as it takes only one parameter, the %1
argument:
FmtSetupMessage1(msgSomeMessageId, 'Argument')
so, the messages that are formatted by the FmtSetupMessage1
function will most likely contain only the %1
argument.
The principle of the [CustomMessages]
section is providing a way to define custom messages, which includes the arguments that you pass them to format the output string. So it's entirely upon you what you will pass to any of the following ways.
In scripting sections you can use the {cm:...}
constants where you can pass the arguments as a comma separated list after the message name. For example this:
[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 into this formatted message:
Lorem Argument 2 ipsum dolor sit Argument 1 amet.
Since the {cm:...}
constant format is more complex than this, I would refer you to help for details.
In the [Code]
section you can use the FmtMessage
function to format the message with this sort of argument support. To get the custom message you can use the CustomMessage
function. Here is a short 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;
Upvotes: 9