Hello,
I have some code to check some components and set tasks checked or unchecked.
I also set the ItemCaption (I want to show user custom caption why my code deselected it), it works as intended on the wpSelectTasks page. But if I press back (so returning to wpSelectTasks) I am getting a "List index out of bounds (-1)"
I am using a LookupTask function to find out the index by name:
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;
[15:39:15,041] Index of "MySQL Installer Utility" task is 1
[15:39:15,107] Index of "MySQL Server 8.0.23 x64" task is 2
[15:39:15,154] Index of "Create databases" task is 3
Pressing back:
[15:39:18,842] Index of "MySQL Installer Utility" task is 1
[15:39:18,851] Index of "MySQL Server 8.0.23 x64" task is -1
[15:39:18,863] Index of "Create databases" task is 3
[15:39:37,204] Exception message:
[15:39:37,218] Message box (OK):
Runtime error (at 83:8564):
List index out of bounds (-1)
I do not understand why after pressing back the index is -1
Code:
if CurPageID = wpSelectTasks then
begin
//If no component related to task is selected, then there is nothing to check and tasks will not be shown.
if WizardIsComponentSelected('MySQL\MySQLInstaller\MySQLServer') then
begin
//Lookup TasksList index. This can differ if amount of tasks is changed.
MySQLInstallerIndex := LookupTask('MySQLInstaller');
MySQLServerIndex := LookupTask('MySQLServer');
MySQLConfigureIndex := LookupTask('MySQLConfigure');
//Always check MySQLInstaller utility task. It is ignored anyway if already installed.
WizardForm.TasksList.Checked[MySQLInstallerIndex] := True;
//Check if any MySQL Server keys are there. Registry keys are in WOW6432Node. Installer is 32-bit so auto will work.
if not RegKeyExists(HKEY_AUTO, 'SOFTWARE\MySQL AB\MySQL Server 8.0') and not RegKeyExists(HKEY_AUTO, 'SOFTWARE\MySQL AB\MySQL Server 5.7') then
begin
Log('RegKeyExists is false. MySQL Server 5.7 and MySQL Server 8.0 are not found in registry');
//MsgBox('RegKey not exist', mbInformation, MB_OK);
//Set caption of dynamic index.
WizardForm.TasksList.ItemCaption[MySQLServerIndex] := 'MySQL Server' + #13#10 + 'No existing MySQL Server installations found';
//Check TasksList checkboxes because no MySQL detected.
WizardForm.TasksList.Checked[MySQLServerIndex] := True;
WizardForm.TasksList.Checked[MySQLConfigureIndex] := True;
end
else
begin
Log('RegKeyExists is true. MySQL Server 5.7 or MySQL Server 8.0 are found in registry');
//MsgBox('RegKeyExist', mbInformation, MB_OK);
//First check for MySQL 8.
if RegQueryStringValue(HKEY_AUTO, 'SOFTWARE\MySQL AB\MySQL Server 8.0', 'Version', MysqlVersion) then
begin
//MySQL 8 is found.
Log(Format('RegKeyExist for MySQL 8: Version=%s', [MysqlVersion]));
//MsgBox('MysqlVersion: ' + MysqlVersion, mbInformation, MB_OK);
//Set caption of dynamic index.
WizardForm.TasksList.ItemCaption[MySQLServerIndex] := 'MySQL Server' + #13#10 + 'Unchecked because already installed MySQL Server version ' + MysqlVersion + ' found!';
//UNcheck TasksList checkboxes because MySQL detected.
WizardForm.TasksList.Checked[MySQLServerIndex] := False;
WizardForm.TasksList.Checked[MySQLConfigureIndex] := False;
end
Can anybody explain what is different to the wpSelectTasks the second time?
Greetings!
Niek