Inno Setup - determine which tasks correspond to TaskList elements (show text on mouse only for certain tasks)
So, I have these tasks comtools
, which, as you can see, may have a different position in the task list, depending on which components were previously selected. Moreover, they may be absent altogether if the user does not want to install these components. I need static text, but only when the cursor is hovering over tasks comtools
.
[Tasks]
Name: "acorig"; Description: "ac original"; GroupDescription: "Choose which version of ac to install:"; Flags: exclusive; Components: ac
Name: "acenh"; Description: "ac enhanced"; GroupDescription: "Choose which version of ac to install:"; Flags: exclusive unchecked; Components: ac
Name: "ac2comtools"; Description: "ac2"; GroupDescription: "Also install community-made tools (unsupported) for:"; Flags: unchecked; Components: ac2
Name: "bccomtools"; Description: "bc"; GroupDescription: "Also install community-made tools (unsupported) for:"; Flags: unchecked; Components: bc
Name: "bc2comtools"; Description: "bc2"; GroupDescription: "Also install community-made tools (unsupported) for:"; Flags: unchecked; Components: bc
Name: "bc3comtools"; Description: "bc3"; GroupDescription: "Also install community-made tools (unsupported) for:"; Flags: unchecked; Components: bc3
Name: "bc4comtools"; Description: "bc4"; GroupDescription: "Also install community-made tools (unsupported) for:"; Flags: unchecked; Components: bc4
Yes, I've seen this one , but it ties the description to the index, which is not practical here. In addition, this code shows a description for all items in the TasksList
.
---- ---- Edit
So, the only change I made to the code after Martin's answer (besides moving everything to the task page) was to add Martin's function and edit HoverComponentChanged
like this:
procedure HoverComponentChanged(Index: Integer); var Description: string; begin case Index of -1: Description := ''; LookupTask('ac2comtools'): Description := 'This is the description of AC2'; LookupTask('bccomtools'): Description := 'This is the description of BC'; LookupTask('bc2comtools'): Description := 'This is the description of BC2'; LookupTask('bc3comtools'): Description := 'This is the description of BC3'; else Description := ''; end; TaskLabel.Caption := Description; end;
-1
is fail-safe because when one of the components is not selected, the index for the corresponding task is -1
, which means that you will see a description for the first canceled component in this list when your cursor is out of bounds TasksList
.
source to share
There really isn't an easy way to determine which tasks correspond to items TaskList
.
The quick and dirty way is to use the product description.
In this case, it is better to define the description using a custom message so you can reference it in code. And this is necessary 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 to decide which tasks to show.
Use the functionWizardIsComponentSelected
( IsComponentSelected
before installing Inno 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 automatically create a complete mapping of the task name and the item index TaskList
, you can do something like this every time the task list changes, that is, when you call : CurPageChanged(wpSelectTasks)
- Remember the current state of the task
- Check all task flags
- Read to get the names of all tasks
WizardSelectedTasks(False)
- Generating mapping
- Restore the previous state of the task.
It is relatively easy when there are only checkboxes, not radio buttons (that is, no exclusive
flag task ).
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 Tasks
to find the corresponding index of the issue:
AC2ComToolsIndex := Tasks.IndexOf('ac2comtools');
Although, since you have exclusive
tasks, you need a lot more complex code.
source to share