changing text font of custom message in inno setup - inno-setup

Is there a way to change the color of a custom message in inno setup?
here is my test code
[Setup]
AppName=My Program
AppVersion=1.5
WizardStyle=modern
DefaultGroupName=My Program
UninstallDisplayIcon={app}\MyProg.exe
OutputDir=userdocs:Inno Setup Examples Output
CreateAppDir=False
[Components]
Name: "program"; Description: "{cm:mymessage}"
[Icons]
Name: "{group}\My Program"; Filename: "{app}\MyProg.exe"
[CustomMessages]
mymessage=this is my message
any idea on how I might accomplish this
I found I can change messages using message id, could something like this be used for custom messages?
[Code]
procedure InitializeWizard();
begin
WizardForm.WelcomeLabel2.Font.Style := [fsBold]; //Bold
WizardForm.WelcomeLabel2.Font.Color := clRed; // And red colour
end;

There is no official way how to do that in vanilla Inno Setup.
Better to say: it is possible only with changing the sources and recompiling the Inno Setup because assigning the color to text is ignored:
WizardForm.ComponentsList.Font.Color := clRed;
WizardForm.ComponentsList.Color := clBlue;
Some 3rd party extensions (Graphical Installer - I am it's developer) or modified Inno Setup version allows that.

Related

How do I call an external iss script and use the functions within from a main Inno Setup script under Code section?

I have an Inno Setup script with a code section for some basic stuff. But I also have another Inno Setup script file (.iss) that deals with Windows services specifically. I would like to call these functions/procedures directly from my main script. So how do I #include the services.iss file into my main script so that I can call its functions from the Code section?
I've seen some examples on the net indicating how to split the file section using this method, which is great, but I want to be able to split the code section using common code scripts between installations. I could find mention of it here and there, but nowhere does it tell you how to do it.
As you have mentioned yourself, use the #include pre-processor directive.
If you have a common code file like common.pas:
procedure CommonProcedure;
begin
// ...
end;
You can include it into the main .iss script like:
[Code]
#include "common.pas"
function InitializeSetup(): Boolean;
begin
// Calling procedure included from the common.pas
CommonProcedure;
Result := True;
end;
The extension does not really matter. I've used .pas, as the file it's purely a Pascal (Script) code. But if you prefer .iss, it's your choice. Though then, syntactically it would be more appropriate to include section name into the file:
[Code]
procedure CommonProcedure;
begin
// ...
end;
And include the file out-side of the [Code] section:
#include "common.pas"
[Code]
function InitializeSetup(): Boolean;
begin
// Calling procedure included from the common.pas
CommonProcedure;
Result := True;
end;
This approach even gives you greater flexibility, e.g. in case you need some support files for your code:
[Files]
Source: "InnoCallback.dll"; Flags: dontcopy
[Code]
procedure CommonProcedure;
begin
// ...
end;
(Though it's just a matter of coding style. Technically, it does not really matter, as the sections can be mixed in any way. So you can have [Code] section, followed by [Files] section, followed by another [Code] section).

Inno Setup ISPP, how to define Processor Architecture...?

I'm trying define a x86 x64 preprocessor variable in Inno Setup with this code, but it doesn´t work:
#if IsWin64
#define OSBITS "x64"
#else
#define OSBITS "x86"
#endif
Can someone help me to define OSBITS?
Thanks in advance...
The #if is a preprocessor directive. As such, it is evaluated on compile-time. You cannot use it to select a value based on target's machine architecture as that is known on runtime (install-time) only.
For this reason there's even no IsWin64 preprocessor function.
If you need to use the x64/x86 value in some Inno Setup directive, you can usually use a scripted constant.
A simple example:
[Setup]
AppName=My Program {code:OSBits}
[Code]
function OSBits(Param: String): string;
begin
if IsWin64 then
Result := 'x64'
else
Result := 'x86';
end;

Emitting value from Setup section in included file

I have read in an answer by TLama how to emit a setting into a code section so it can be used at runtime. This works as long as it is in one file. However, if I have
test.iss
#include "include.iss"
[Setup]
AppId={{87E1AD40-F32B-4EF7-A2FF-5B508814068A}
AppName=My Program
AppVersion=1.5
DefaultDirName=My Program
and include.iss
[Code]
procedure InitializeWizard;
var
S: string;
begin
S := '{#SetupSetting("AppId")}';
MsgBox(S, mbInformation, MB_OK);
end;
I get an empty message box. The documentation on SetupSetting is not very verbose.
Is there a solution for this? My setup is a bit larger and I do the #include to avoid duplicate code for different editions of the same program.
The key is this part of SetupSetting documentation:
parses [Setup] section in current translation
Where the "current translation" is defined as:
refers to current output of ISPP, the translated (preprocessed) part of the script up to the point (or line) which ISPP is currently processing.
At the point of your #include, the AppId is not defined yet.
A solution is to move the #include below the Setup section:
[Setup]
AppId={{87E1AD40-F32B-4EF7-A2FF-5B508814068A}
...
#include "include.iss"
Or, as you have found yourself, use a preprocessor variable.
It is possible to workaround the issue by defining a pre-processor value for the AppId, e.g. AppGUID, and then use it instead:
test.iss
#define AppGUID "{87E1AD40-F32B-4EF7-A2FF-5B508814068A}"
#include "include.iss"
[Setup]
AppId={{#AppGUID}
AppName=My Program
AppVersion=1.5
DefaultDirName=My Program
include.iss
[Code]
procedure InitializeWizard;
var
S: string;
begin
S := '{#AppGUID}';
MsgBox(S, mbInformation, MB_OK);
end;

How to optionally include certain code for certain features?

In Inno Setup, I have a main script which is the "core system", meaning everything which is absolutely needed for our software to install/run at all. Additionally, I'm writing script files for each major feature which may or may not be compiled into the installer. At the top of the main script file, I include other script files...
#include "AdditionalOption.iss"
#include "AnotherOption.iss"
When compiling this main script, the person compiling may choose whether or not to compile these certain options in the installer at all (to spare file size for various reasons).
The problem arises when I have specific code in the main script which depends on something in one of these additional scripts. For example...
procedure InitializeWizard();
begin
//Creates custom wizard page only if "AdditionalOption.iss" is compiled
CreatePageForAdditionalOption;
//Creates custom wizard page only if "AnotherOption.iss" is compiled
CreatePageForAnotherOption;
end;
InitializeWizard can only be defined once, but I need to call code in it conditionally depending on whether or not those other scripts were included. Those procedures reside in their appropriate script files, so of course they don't exist if user excluded that other script file.
In Delphi, I can use conditionals like so:
{$DEFINE ADD_OPT}
{$DEFINE ANO_OPT}
procedure InitializeWizard();
begin
{$IFDEF ADD_OPT}
CreatePageForAdditionalOption;
{$ENDIF}
{$IFDEF ANO_OPT}
CreatePageForAnotherOption;
{$ENDIF}
end;
Of course this isn't actually Delphi though. How can I do such a thing in Inno Setup?
Inno Setup has a Preprocessor which enables you to make use of #ifdef, #else and #endif which you can set via the iscc.exe /D command line param(s). You can define multiple #ifdef's and set them via multiple /D's.
; Command line param => /DADD_OPT
#ifdef ADD_OPT
...
#else
...
#endif
I've used them to override default values:
; Command line param => /DENVIRONMENT=Prod
#ifdef ENVIRONMENT
#define Environment ENVIRONMENT
#else
#define Environment "Beta"
#endif
A little bit more digging around and I figured it out. Just like my example above...
{$DEFINE ADD_OPT}
{$DEFINE ANO_OPT}
procedure InitializeWizard();
begin
{$IFDEF ADD_OPT}
CreatePageForAdditionalOption;
{$ENDIF}
{$IFDEF ANO_OPT}
CreatePageForAnotherOption;
{$ENDIF}
end;
It can be replicated in Inno Setup like so...
#define Public ADD_OPT
#define Public ANO_OPT
procedure InitializeWizard();
begin
#ifdef ADD_OPT
CreatePageForAdditionalOption;
#endif
#ifdef ANO_OPT
CreatePageForAnotherOption;
#endif
end;

How do I use "code" in Inno Setup's [Files] section?

I want to dynamically derive the source folder (and destination folder) for 32/64 bit installations. So how can I specify that in the [Files] section of Inno setup.
The following gives a compilation error:->
[Files]
Source: {#MySourcePath}\{code:GetSourceLibFolder}\*.jar; DestDir: {code:GetAppDir}\lib\;
I have the GetSourceLibFolder() and GetAppDir() function defined in the code section.
The functions are very simple and just return a variable:
function GetSourceLibFolder(Param: String): String;
begin
Result:= SourceLibFolder;
end;
function GetSourceBinFolder(Param: String): String;
begin
Result:= SourceBinFolder;
end;
Thanks !
The source path needs to be used at compile time (unless you have the external flag) which means you must use ISPP and a #define. The [Code] section is only for run/install time code so will work for the target path.
If you provide the code for your GetSourceLibFolder function, someone can convert it to ISPP.

Resources