Martin Ba
Martin Ba

Reputation: 38861

How can I add dynamic text to a Description parameter of a setup section in Inno Setup?

I have a [Tasks] definition in my Inno Setup Script, that should contain some dynamic text:

[CustomMessages]
msgTaskGroupWithFormat=Group Head (Detail: %1) for frobnication

[Tasks]
Name: frobnicateTask; Description: "Frobnicate <dynamic>"; \
  GroupDescription:{cm:msgTaskGroupWithFormat, 'dynamic text to be embedded into CustomMessage'};" \
  Flags: unchecked;

That is, the Description text and the GroupDescription text should not be hardcoded in the setup script or via a CustomMessage, but should contain some dynamic text resolved at runtime.

Ideally, I could still use a CustomMessage via {cm:msgWithFmt, param} and only have the param part be dynamically resolved.

Is this possible in Inno Setup?

Upvotes: 1

Views: 273

Answers (1)

Martin Ba
Martin Ba

Reputation: 38861

This can be done via the {code:...} constant.

It can be used directly, and it also can be combined with the {cm:...}constant for custom messages:

[Code]
function DynamicText1(p: String): String;
begin
  Result := '...';
end;

function DynamicText2(p: String): String;
begin
  Result := '...';
end;
[CustomMessages]
msgTaskGroupWithFormat=Group Head (Detail: %1) for frobnication

[Tasks]
Name: frobnicateTask; Description: {code:DynamicText1}; \ 
  GroupDescription:{cm:msgTaskGroupWithFormat, {code:DynamicText2}};" \
  Flags: unchecked;

The only thing to look out for here is that the dynamic text must be computable at the time Inno Setup resolves the text for the descriptions! That is, as with all Code in Inno one must check when the callback happens and whether all Info is already available at this point.

Upvotes: 2

Related Questions