且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Inno Setup当另一个任务被选中时,取消选中一个任务

更新时间:2022-06-20 02:58:11

  1. WizardForm.TasksList.OnClickCheck不是由Inno Setup本身分配的(与WizardForm.ComponentsList.OnClickCheck相反),因此您不能调用它.

  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:

  • 完全删除DefaultTasksClickCheck;
  • 或者如果希望在以后的Inno Setup版本中使用该事件以防万一,请在调用它之前检查它是否为nil.
  • 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.

您不知道最近在OnClickCheck处理程序中检查了哪些任务.因此,您必须记住先前检查过的任务才能正确决定要取消选择的任务.

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;

在Inno Setup 6中,除了使用索引之外,您还可以使用 WizardSelectTasks .例如,请参见 Inno设置:如果选择了另一个组件,如何自动选择一个组件?.

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?.

有关检测已检查项目的更通用解决方案,请参见 Inno Setup在TasksList中检测已更改的任务/项目. OnClickCheck事件.