本文介绍了Inno Setup在TasksList.OnClickCheck事件中检测更改的任务/项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被OnClickCheck属性困在简单的情况下.问题是,每次打开backup任务时,我都会看到一个Msgbox,而且(在它打开时)在按下uninst任务时也出现了OnClickCheck!似乎OnClickCheck检查所有点击,但是我只需要检查第一个任务的点击即可.

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.

将确切的任务数(WizardForm.TasksList.OnClickCheck[0])添加到"WizardForm.TasksList.OnClickCheck"是合乎逻辑的,但是编译器对此并不认同.

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;

推荐答案

无法确切说明OnClickCheck事件中更改了哪些任务(列表项).

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

要知道用户检查了哪个项目,可以使用ItemIndex属性.用户只能检查选定的项目.

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

尽管您具有任务层次结构,但由于子项/父项的更改,即使未选择的任务也可以由安装程序自动切换.因此,要告知所有更改,您只需记住上一个状态,并在调用OnClickCheck时将其与当前状态进行比较.

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;


除了使用索引之外,您还可以将任务名称与 WizardSelectedTasks一起使用 WizardIsTaskSelected .例如,请参见 Inno设置:如果选择了另一个组件,如何自动选择一个组件?


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?

另请参阅:

  • 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

这篇关于Inno Setup在TasksList.OnClickCheck事件中检测更改的任务/项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 21:38