Question

I'm writing an InnoSetup installer that includes these sections:

[Types]
Name: "ChooseVers"; Description: "Install support for WordPerfect versions:"; Flags: iscustom

[Components]
Name: "InstallForWP51"; Description: "Install support for WordPerfect 5.1"; Types: ChooseVers; Flags: checkablealone
Name: "InstallForWP62"; Description: "Install support for WordPerfect 6.2"; Types: ChooseVers; Flags: checkablealone

When the user runs the installer, it presents two checkboxes for the two items listed under Components, and the user can check either or both.

What I want to do is display a message if the user does not check either box, so that nothing gets installed. As it stands, the user simply sees a somewhat misleading message listing nothing under the the list of actions that will be performed, and the installer then closes. There's nothing seriously wrong with this, but it would be better to be more informative.

I'll be very grateful for any help with this.

Was it helpful?

Solution

You can use the IsComponentSelected function to check whether the component is selected or not. And for the validation might be good to use the NextButtonClick event method, which allows you to stay on the page. In the following script is shown, how to display a confirmation message box if none of the components is selected and allows the user to stay on the page or continue:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Types]
Name: "ChooseVers"; Description: "Install support for WordPerfect versions:"; Flags: iscustom

[Components]
Name: "InstallForWP51"; Description: "Install support for WordPerfect 5.1"; Types: ChooseVers; Flags: checkablealone
Name: "InstallForWP62"; Description: "Install support for WordPerfect 6.2"; Types: ChooseVers; Flags: checkablealone

[Code]
function NextButtonClick(CurPageID: Integer): Boolean;
begin
  Result := True;
  if (CurPageID = wpSelectComponents) and not (IsComponentSelected('InstallForWP51') or
    IsComponentSelected('InstallForWP62')) then
  begin
    Result := MsgBox('None of the components is selected. This won''t install ' +
      'anything. Are you sure you want to continue ?', mbConfirmation, MB_YESNO) = IDYES;
  end;
end;

Or the same shortened to less readable form:

[Code]
function NextButtonClick(CurPageID: Integer): Boolean;
begin
  Result := (CurPageID <> wpSelectComponents) or (IsComponentSelected('InstallForWP51') or
    IsComponentSelected('InstallForWP62')) or (MsgBox('None of the components is selected. ' +
    'This won''t install anything. Are you sure you want to continue ?', mbConfirmation,
    MB_YESNO) = IDYES);
end;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top