Search code examples
inno-setuppascalscript

Display an image when a task is selected


I want the tasks display a different image when one of them is checked.

For example, if I have three different tasks:

Task 1: Standard version
Task 2: Lite version
Task 3: Pro version
  • when Task 1 is checked must display an image.
  • when Task 2 is checked must hide Task 1 image and display Task 2 image.
  • When Task 3 is checked must hide others below tasks image and show Task 3 image.

Here some code

[Code]
{ RedesignWizardFormBegin } { Don't remove this line! }
{ Don't modify this section. It is generated automatically. }
var
  BitmapImage1: TBitmapImage;

procedure RedesignWizardForm;
begin
  { BitmapImage1 }
  BitmapImage1 := TBitmapImage.Create(WizardForm);
  with BitmapImage1 do
  begin
    Parent := WizardForm.SelectTasksPage;
    Left := ScaleX(320);
    Top := ScaleY(88);
    Width := ScaleX(57);
    Height := ScaleY(57);
    ExtractTemporaryFile('WizardForm.BitmapImage1.bmp');
    Bitmap.LoadFromFile(ExpandConstant('{tmp}\WizardForm.BitmapImage1.bmp'));
  end;

  with WizardForm.TasksList do
  begin
    Width := ScaleX(257);
    Height := ScaleY(200);
    Visible := False;
  end;
end;

Solution

    • Use WizardIsTaskSelected (IsTaskSelected in older versions of Inno Setup) to find out what tasks have been selected.
    • Handle WizardForm.TasksList.OnClickCheck and CurPageChanged to detect selection change and update image accordingly.
    [Files]
    Source: "lite.bmp"; Flags: dontcopy
    Source: "pro.bmp"; Flags: dontcopy
    Source: "std.bmp"; Flags: dontcopy
    
    [Tasks]
    Name: std; Description: "Standard version"; Flags: exclusive
    Name: lite; Description: "Lite version"; Flags: exclusive
    Name: pro; Description: "Pro version"; Flags: exclusive
    
    [Code]
    var
      BitmapImage1: TBitmapImage;
    
    procedure UpdateTasksImage;
    var
      Image: string;
    begin
      if WizardIsTaskSelected('pro') then Image := 'pro.bmp'
        else
      if WizardIsTaskSelected('lite') then Image := 'lite.bmp'
        else
      if WizardIsTaskSelected('std') then Image := 'std.bmp'
        else Image := '';
    
      if Image <> '' then
      begin
        ExtractTemporaryFile(Image); 
        BitmapImage1.Bitmap.LoadFromFile(ExpandConstant('{tmp}\' + Image));
        BitmapImage1.Visible := True;
      end
        else
      begin
        BitmapImage1.Visible := False;
      end;
    end;
    
    procedure TasksListClickCheck(Sender: TObject);
    begin
      { Update image, when task selection changes }
      UpdateTasksImage;
    end;
    
    procedure CurPageChanged(CurPageID: Integer);
    begin
      { Update image, when task page is entered }
      { (as tasks can be selected by changing setup type or components) }
      if CurPageID = wpSelectTasks then
      begin
        UpdateTasksImage;
      end;
    end;
    
    procedure InitializeWizard;
    begin
      BitmapImage1 := TBitmapImage.Create(WizardForm);
      with BitmapImage1 do
      begin
        Parent := WizardForm.SelectTasksPage;
        Left := ScaleX(320);
        Top := ScaleY(88);
        Width := ScaleX(57);
        Height := ScaleY(57);
      end;
    
      with WizardForm.TasksList do
      begin
        Width := ScaleX(257);
        Height := ScaleY(200);
      end;
    
      WizardForm.TasksList.OnClickCheck := @TasksListClickCheck
    end;
    

    enter image description here

    enter image description here


    Though it seems to me, that your "tasks" should actually be setup types or components. It does not make sense to me, that a user can select combinations of "standard", "lite" and "pro". Shouldn't those be a distinct options?