Inno Setup Detect changed task/item in TasksList.OnClickCheck event

前端 未结 1 866
萌比男神i
萌比男神i 2020-12-18 13:17

I\'m stuck on simple situation with OnClickCheck property. The problem is that I see a Msgbox every time I turn on backup task, but al

1条回答
  •  既然无缘
    2020-12-18 13:46

    There's no way tell exactly what task (list item) was changed in the OnClickCheck event.

    To tell which item was checked by the user, you can use the ItemIndex property. The user can check only the selected item.

    Though if you have a task hierarchy, even unselected task can be toggled automatically by the installer due to a change in child/parent items. So to tell all changes, all you can do is to remember the previous state and compare it against the current state, when the OnClickCheck is called.

    var
      TasksState: array of TCheckBoxState;
    
    procedure TasksClickCheck(Sender: TObject);
    var
      I: Integer;
    begin
      for I := 0 to WizardForm.TasksList.Items.Count - 1 do
      begin
        if TasksState[I] <> WizardForm.TasksList.State[I] then
        begin
          Log(Format('Task %d state changed from %d to %d',
                     [I, TasksState[I], WizardForm.TasksList.State[I]]));
          TasksState[I] := WizardForm.TasksList.State[I];
        end;
      end;
    end;
    
    procedure CurPageChanged(CurPageID: Integer);
    var
      I: Integer;
    begin
      if CurPageID = wpSelectTasks then
      begin
        { Only now is the task list initialized (e.g. based on selected setup }
        { type and components). Remember what is the current/initial state. }
        SetArrayLength(TasksState, WizardForm.TasksList.Items.Count);
        for I := 0 to WizardForm.TasksList.Items.Count - 1 do
          TasksState[I] := WizardForm.TasksList.State[I];
      end;
    end;
    
    procedure InitializeWizard();
    begin
      WizardForm.TasksList.OnClickCheck := @TasksClickCheck;
    end;
    

    Instead of using indexes, you can also use task names with use of WizardSelectedTasks or WizardIsTaskSelected. For an example, see Inno Setup: how to auto select a component if another component is selected?


    Also see:

    • Inno Setup ComponentsList OnClick event
    • Inno Setup Uncheck a task when another task is checked
    • Inno Setup - Show children component as sibling and show check instead of square in checkbox

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