Inno Setup - Identify, what tasks correspond to the items of TaskList (to show text on mouse over for certain tasks only)

元气小坏坏 提交于 2019-12-06 13:02:08

There's really no straightforward way to identify, what tasks correspond to the items of TaskList.


Quick and dirty way is to use item description.

In this case, it's better to define the description using a custom message, so that you can refer to it in the code. And it's a must anyway, if your installer is localized.

[CustomMessages]
AC2ComTools=ac2

[Tasks]
Name: "ac2comtools"; Description: {cm:AC2ComTools}
[Code]

function LookupTask(TaskCustomMessage: string): Integer;
var
  Description: string;
begin
  Description := CustomMessage(TaskCustomMessage);
  Result := WizardForm.TasksList.Items.IndexOf(Description);
  Log(Format('Index of "%s" task is %d', [Description, Result]));
end;

Use it like:

AC2ComToolsIndex := LookupTask('ac2comtools');

Another way is to reproduce the logic of Inno Setup for deciding, what tasks to show.

Use WizardIsComponentSelected function (IsComponentSelected before Inno Setup 6.0.2).

{ Before Inno Setup 6.0.2, use IsComponentSelected. }
if WizardIsComponentSelected('ac2') then
begin
  if WizardIsComponentSelected('ac') then AC2ComToolsIndex := 4
    else AC2ComToolsIndex := 1;
end
  else AC2ComToolsIndex := -1;

If you want to create a full mapping from task name to TaskList item index automatically, you can do something like this each time the task list changes, i.e. on call to CurPageChanged(wpSelectTasks):

  • Remember current task state
  • Check all task checkboxes
  • Read WizardSelectedTasks(False) to get names of all tasks
  • Generate the mapping
  • Restore previous task state.

This is relatively easy, when there are only checkboxes, not radio buttons (i.e. no task with exclusive flag).

var
  Tasks: TStringList;

procedure CurPageChanged(CurPageID: Integer);
var
  TasksChecked: array of Boolean;
  I: Integer;
begin
  if CurPageID = wpSelectTasks then
  begin
    SetArrayLength(TasksChecked, WizardForm.TasksList.Items.Count);
    { Remember current task state + Check all task checkboxes }
    for I := 0 to WizardForm.TasksList.Items.Count - 1 do
    begin
      TasksChecked[I] := WizardForm.TasksList.Checked[I];
      WizardForm.TasksList.Checked[I] := True;
    end;
    Tasks := TStringList.Create;
    Tasks.CommaText := WizardSelectedTasks(False);  
    for I := 0 to WizardForm.TasksList.Items.Count - 1 do
    begin
      { Insert blank items for "group descriptions" }
      if WizardForm.TasksList.ItemObject[I] = nil then
        Tasks.Insert(I, '');
      { Restore previous task state }
      WizardForm.TasksList.Checked[I] := TasksChecked[I];
    end;
  end;
end;

Now you can use the Tasks to lookup corresponding task index:

AC2ComToolsIndex := Tasks.IndexOf('ac2comtools');

Though as you have exclusive tasks, you would need much more complicated code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!