Inno Setup Uncheck a task when another task is checked

后端 未结 1 1319
孤城傲影
孤城傲影 2021-01-07 07:29

I am trying to intercept the WizardForm.TasksList.OnClickCheck event so that I can uncheck a task when another task is selected. I know that normally radio butt

相关标签:
1条回答
  • 2021-01-07 07:39
    1. The WizardForm.TasksList.OnClickCheck is not assigned by the Inno Setup itself (contrary to WizardForm.ComponentsList.OnClickCheck), so you cannot call it.

      To fix the problem, either:

      • completely remove the DefaultTasksClickCheck;
      • or if you want to be covered in case the event starts being used in future versions of Inno Setup, check if it is nil before calling it.
    2. You cannot know what task was checked most recently in the OnClickCheck handler. So you have to remember the previously checked task to correctly decide what task to unselect.

    [Tasks]
    Name: Task1; Description: "Task1 Description"
    Name: Task36; Description: "Task36 Description"; Flags: unchecked
    
    [Code]
    
    var
      DefaultTasksClickCheck: TNotifyEvent;
      Task1Selected: Boolean;
    
    procedure UpdateTasks;
    var
      Index: Integer;
    begin
      { Task1 was just checked, uncheck Task36 }
      if (not Task1Selected) and IsTaskSelected('Task1') then
      begin
        Index := WizardForm.TasksList.Items.IndexOf('Task36 Description');
        WizardForm.TasksList.CheckItem(Index, coUncheck);
        Task1Selected := True;
      end
        else 
      { Task36 was just checked, uncheck Task1 }
      if Task1Selected and IsTaskSelected('Task36') then
      begin
        Index := WizardForm.TasksList.Items.IndexOf('Task1 Description');
        WizardForm.TasksList.CheckItem(Index, coUncheck);
        Task1Selected := False;
      end;
    end;
    
    procedure TasksClickCheck(Sender: TObject);
    begin
      if DefaultTasksClickCheck <> nil then
        DefaultTasksClickCheck(Sender);
      UpdateTasks;
    end;
    
    procedure CurPageChanged(CurPageID: Integer);
    begin
      if CurPageID = wpSelectTasks then
      begin
        { Only now is the task list initialized, check what is the current state }
        { This is particularly important during upgrades, }
        { when the task does not have its default state }
        Task1Selected := IsTaskSelected('Task1');
      end;
    end;
    
    procedure InitializeWizard();
    begin
      DefaultTasksClickCheck := WizardForm.TasksList.OnClickCheck;
      WizardForm.TasksList.OnClickCheck := @TasksClickCheck;
    end;
    

    In Inno Setup 6, instead of using indexes, you can also use task names with use of WizardIsTaskSelected and WizardSelectTasks. For an example, see Inno Setup: how to auto select a component if another component is selected?.


    For a more generic solution to detecting what item has been checked, see Inno Setup Detect changed task/item in TasksList.OnClickCheck event.

    0 讨论(0)
提交回复
热议问题