Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
686 views
in Technique[技术] by (71.8m points)

pascalscript - Inno Setup Detect changed 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;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...