Search code examples
inno-setuppascalscript

TNewCheckListBox Checked not being updated


I'm trying to write an installer in Inno Setup that includes a page where a TNewCheckListBox is created and then used to populate a selection of choices on the next page:

var
  ListBox:         TNewCheckListBox;
  SelectedConfigs: array of Integer;

function ConfigurationPage(): Integer;
var
  Page: TWizardPage;
  I:    Integer;
begin
  Page := CreateCustomPage(wpSelectComponents, 'Select Configuration', 
    'Please select the configuration you would like to install to.');

  ListBox := TNewCheckListBox.Create(Page);
  ListBox.Parent := Page.Surface;
  ListBox.Left := ScaleX(0);
  ListBox.Top := ScaleY(0);
  ListBox.Width := Page.SurfaceWidth;
  ListBox.Height := Page.SurfaceHeight;
  ListBox.BorderStyle := bsNone;

  for I := 0 to GetArrayLength(ConfigurationNames) - 1 do
  begin
    ListBox.AddCheckBox(
      ConfigurationNames[I], '', 0, False, True, False, False, nil);
  end;

  ListBox.ItemIndex := 0;
  Result := Page.ID;
end;

procedure PortSelectionPage(PageID: Integer);
var
  Page:         TWizardPage;
  ArrayLength:  Integer;
  I:            Integer;
begin

  Page := CreateCustomPage(PageID, 'Select Port', 
    'Please select the port you want the configurations to receive on.');
       
  for I := 0 to ListBox.Items.Count - 1 do
  begin
    Log(Format('ListBox[%d], %s is checked? %d', [
      I, ListBox.Items[I], ListBox.Checked[I]]));
    if ListBox.Checked[I] then
    begin
      ArrayLength := GetArrayLength(SelectedConfigs);
      SetArrayLength(SelectedConfigs, ArrayLength + 1);
      SelectedConfigs[ArrayLength] := I;
      Log(Format('Config %d was selected...', [I]));
    end;
  end;
end;

procedure InitializeWizard;
var                         
  PageID:           Integer;
begin
  PageID := ConfigurationPage;                                            
  PortSelectionPage(PageID);
end;

The problem I'm having is that, regardless of the selections I make in the ConfigurationPage procedure, the SelectedConfigs array is not being updated and my debugging messages are showing that none of the options are selected. Before creating the PortSelectionPage procedure, the code lived on the CurStepChanged event handler so I'm not sure if the issue is with my having moved the code to a different page or if there's something else going on here. Do I need to force an update to the component or should I be using event handlers instead? If so, how would I implement one for this usecase?


Solution

  • Your whole code is executed from InitializeWizard event function. Hence even before the installer wizard is shown.

    You have to query the checkbox states only after the user changes them. For example, from some of these events: