I'm trying to create a single installer for both normal and portable installs. For the portable install I am disabling all icons and uninstaller creation.
The only problem I am stuck at is how to disable program group page when running the portable install. Am I misunderstanding something here?
[Setup]
;This works as expected
Uninstallable=not IsPortable()
;This does NOT work, can't compile (DisableProgramGroupPage=yes alone compiles fine)
DisableProgramGroupPage=yes IsPortable()
Compilation fails with error
Value of [Setup] section directive ... is invalid.
This is the IsPortable() function:
function IsPortable(): Boolean;
begin
if(StandardRadioButton.Checked = True) then
Result := False
else
Result := True;
end;
(Elaborating on #TLama's comment)
The DisableProgramGroupPage does not support "boolean expression":
[Setup]: DisableProgramGroupPage
Valid values: auto, yes, or no
Contrary to Uninstallable:
[Setup]: Uninstallable
Valid values: yes or no, or a boolean expression
You can use ShouldSkipPage event function instead:
function ShouldSkipPage(PageID: Integer): Boolean;
begin
Result := False;
if PageID = wpSelectProgramGroup then
begin
Result := IsPortable;
end;
end;
Related
During the execution of the dll the installer crashes on these methods
The methods are taken from the file nsis.pas
function PopString(): string;
var
th: pstack_t;
begin
if integer(g_stacktop^) <> 0 then begin
th := g_stacktop^;
Result := PChar(#th.text);
g_stacktop^ := th.next;
GlobalFree(HGLOBAL(th));
end;
end;
procedure PushString(const str: string='');
var
th: pstack_t;
begin
if integer(g_stacktop) <> 0 then begin
th := pstack_t(GlobalAlloc(GPTR, SizeOf(stack_t) + g_stringsize));
lstrcpyn(#th.text, PChar(str), g_stringsize);
th.next := g_stacktop^;
g_stacktop^ := th;
end;
end;
It looks like nsis.pas is perhaps not compatible with every Delphi version when compiling as Unicode. You did not specify your version so I don't know if your string type is AnsiString or WideString or UnicodeString.
I don't really know Pascal/Delphi anymore but I was able to get it working in FreePascal with this version. I'll try to fix it for the next release.
Make sure UNICODE is defined when using this in a Unicode plug-in.
The problem was very easy to solve
It was necessary to call Init() from nsis.pas
and then everything worked
I am trying to get Inno Setup define value in Code section but not with {#VersionTool1}. I need to pass defined name dynamically, because there are a lot of them (I want to avoid large switch case). I tried SetupSetting but it's not in Setup section (it's before it). Is there any way to do this?
#define VersionTool1 2019.01.1111
#define VersionTool2 2020.02.2111
...
[Code]
procedure SetSelectedTool(ToolName: String);
var
CurrentTool: string;
begin
...
CurrentTool := 'Version' + ToolName;
CurrentToolVersion := {#CurrentTool};
...
end;
Value of local variable CurrentTool wil for example be 'VersionTool1' and I want to get value of VersionTool1 preprocessor variable which is 2020.02.2111.
It's not possible, see Evaluate preprocessor macro on run time in Inno Setup Pascal Script.
But there are other solutions.
For example:
[Code]
var
ToolNames: TStringList;
ToolVersions: TStringList;
function InitializeSetup(): Boolean;
begin
ToolNames := TStringList.Create;
ToolVersions := TStringList.Create;
#define AddToolVersion(Name, Version) \
"ToolNames.Add('" + Name + "'); ToolVersions.Add('" + Version +"');"
#emit AddToolVersion('Tool1', '2019.01.1111')
#emit AddToolVersion('Tool2', '2020.02.2111')
{ ... }
Result := True;
end;
(of course, the above makes sense only if you actually do not hardcode the version numbers, but use a code that only a preprocessor can do – something like GetStringFileInfo, what I've understood from your comments that you plan to)
And then you can have a function like:
function GetToolVersion(ToolName: string): string;
var
I: Integer;
begin
I := ToolNames.IndexOf(ToolName);
if I >= 0 then Result := ToolVersions[I];
end;
Another similar questions:
Array Variables and dynamic access in [Code] section
Scripting capabilities in the Registry section
I am trying to use the [ISPP] section to define a hexadecimal color which will later be used in the [Code] section as a spot color, the value of which may change in the future, but I am getting a type mismatch error when running. Here are the relevant sections from the code:
[ISPP]
#define ColorPetrol "$C8C264"
[Code]
procedure InitializeWizard();
var
PortLabel: TNewStaticText;
begin
PortLabel := TNewStaticText.Create(WizardForm);
PortLabel.Caption := 'Port';
PortLabel.Top := ScaleY(78);
PortLabel.Parent := Page.Surface;
PortLabel.Font.Color := ExpandConstant('{#ColorPetrol}');
end;
I am assuming the error is caused by the define constant being a string and the PortLabel.Font.Color requiring a hex value. How can the constant be defined in the [ISPP] section and used in this way correctly?
Just use PortLabel.Font.Color := {#ColorPetrol};. ExpandConstant() is for expanding built-in Inno Setup constants, not for ISPP defines. The latter really are just about textual replacements.
As a side note, I'm not aware of an [ISPP] section. IMO you should just move the define to the [Code] section.
Is it possible to build a script line using a variable and some conditions (have executable that requires different switches depending on what is checked on a custom page. Possibly something like this:
var
linecommand : string;
function FileParams();
begin
if check1 then linecommand := linecommand+' conditionone' end;
if check2 then linecommand := linecommand+' conditiontwo' end;
if check3 then linecommand := linecommand+' conditiontwo' end;
end;
function check123()
begin
if check1 or check2 or check3 then
begin
linecommand='Executable file name.exe '+linecommand;
Shellexec(linecommand);
end;
end;
You can use a {code:...} constant to insert a value calculated in a [Code] function into a specific value within a standard entry that accepts both strings and constants (such as the Parameters value of a [Run] entry).
Or you can write multiple entries and use a Check function to determine which (if any) of them actually get executed.
When I compile the code below, it completes without errors, but when I attempt to run the setup file I get a type mismatch error. Can anyone tell me what might be causing it? (exact error message is "Runtime Error (at 1:66): Type Mismatch.")
[Setup]
DefaultDirName={code:AppDir}\MyApp
[Code]
function AppDir(Param: String): String;
var
Check: Integer;
begin
Check := GetWindowsVersion();
if Check = 6.0 then
Result := ExpandConstant('{userdocs}')
else
Result := ExpandConstant('{pf}');
end;
Quoting from the Inno Setup documentation for GetWindowsVersion():
Returns the version number of Windows packed into a single integer. The upper 8 bits specify the major version; the following 8 bits specify the minor version; the lower 16 bits specify the build number. For example, this function will return $05000893 on Windows 2000, which is version 5.0.2195.
You can't compare with a floating point value, you need to extract the parts of the version number, like so:
function AppDir(Param: String): String;
var
Ver: Cardinal;
VerMajor, VerMinor, BuildNum: Cardinal;
begin
Ver := GetWindowsVersion();
VerMajor := Ver shr 24;
VerMinor := (Ver shr 16) and $FF;
BuildNum := Ver and $FFFF;
if VerMajor >= 6 then
Result := ExpandConstant('{userdocs}')
else
Result := ExpandConstant('{pf}');
end;
Note that you should never check VerMajor for equality, as this would fail for either lower or higher Windows versions. Always use <= or >= instead.