Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 also (while it's switched on) OnClickCheckappeared on pressing uninst task too! Seems that OnClickCheck checks all clicks, but I need to check click only on the first task.

It is logical to add to WizardForm.TasksList.OnClickCheck exact number of task (WizardForm.TasksList.OnClickCheck[0]), but compiler doesn't agree with it.

[Tasks]
Name: backup; Description: do backup
Name: uninst; Description: do not create uninstaller
[Code]

procedure TaskOnClick(Sender: TObject); 
begin
  if IsTaskSelected('backup') then 
  begin
    MsgBox('backup task has been checked.', mbInformation, MB_OK) 
  end;
end;

procedure InitializeWizard();
begin
  WizardForm.TasksList.OnClickCheck := @TaskOnClick;
end;
like image 380
Sergei Pimenov Avatar asked Oct 21 '25 01:10

Sergei Pimenov


1 Answers

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
  • Uncheck an Inno Setup task when another task is checked
  • Show Inno Setup children component as sibling and show check instead of square in checkbox
like image 199
Martin Prikryl Avatar answered Oct 27 '25 05:10

Martin Prikryl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!