1
votes

When I define a preprocessor string variable (using the ISPP) that contains a quote/apostrophe, there will be a compiler error when I use the function ExpandConstant in the [Code] section to read this string.

Here's an example .iss script for demonstrating/testing:

#define _AppName "Uli's Program"

[Setup]

AppName={#_AppName}
AppVersion=1.2.3
DefaultDirName={pf}\{#_AppName}

[Code]

function InitializeSetup: Boolean;
begin
  MsgBox(ExpandConstant('{#_AppName}'),
         mbInformation,
         MB_OK);
  Result:=False;
end;

The exact compiler error message is:

comma (',') expected.

Update

This works when the apostrophe is doubled. But now the captions of the wizard pages show the app name with a double apostrophe (because of AppName={#_AppName}).

A similar issue occurs when the #define is removed and the script is altered this way:

[Setup]

AppName=Uli's Program
AppVersion=1.2.3
DefaultDirName={pf}\{#AppName}

[Code]

function InitializeSetup: Boolean;
begin
  MsgBox('{#SetupSetting("AppName")}'),
         mbInformation,
         MB_OK);
  Result:=False;
end;

Now the compiler error message is

Assignment expected.

1
Double up the apostrophe. - Andrew Truckle
Yes, that work's - but now the captions of the wizard pages show the app name with a double apostrophe (because of "AppName={#_AppName}"). - uliF
It seems to me that you can't then: ww1.fileforums.com/showthread.php?p=416825. Others might say otherwise. - Andrew Truckle

1 Answers

0
votes

You can use the macro to create an entry in CustomMessages section.

And then load the custom message in Pascal Script using CustomMessage function.

#define _AppName "Uli's Program"

[CustomMessages]
MyAppName={#_AppName}

[Code]

function InitializeSetup(): Boolean;
begin
  MsgBox(CustomMessage('MyAppName'), mbInformation, MB_OK);
  Result := False;
end;

Another (rather hackish) way is to use StringChange preprocessor function to double the quote in Pascal Script.

#define _AppName "Uli's Program"

[Code]

function InitializeSetup(): Boolean;
begin
  MsgBox('{#StringChange(_AppName, "'", "''")}', mbInformation, MB_OK);
  Result := True;
end;

Note that I do not use ExpandConstant to resolve the preprocessor variable/expression - It's nonsense. See Evaluate preprocessor macro on run time in Inno Setup Pascal Script.


enter image description here