Search code examples
inno-setuppascalscript

Dynamically show the control and content on next screen after ComboBox change in Inno Setup?


When I run this code first time everything works as expected. But once you select Sonitor and then select BBraun, Sonitor controls (label and textbox) doesn't go away they are still on screen.

[Code]
var
  VendorPage, VendorHostPage: TWizardPage;
  VendorText: TNewStaticText;
  VendorEdit: TNewEdit;
  ComboBox: TNewComboBox;
  
procedure ComboBoxChange(Sender: TObject);
begin
  case ComboBox.ItemIndex of
    0:
    begin
      VendorText := TNewStaticText.Create(VendorHostPage);
      VendorText.Anchors := [akLeft, akRight, akBottom];
      VendorText.Caption := 'AssetTracking connects to the BBraun server to recieve the HL7 data';
      VendorText.AutoSize := True;
      VendorText.Parent := VendorHostPage.Surface;

      VendorText := TNewStaticText.Create(VendorHostPage);
      VendorText.Top := ScaleY(25);
      VendorText.Anchors := [akLeft, akRight, akBottom];
      VendorText.Caption := 'BBraun HL7 port:';
      VendorText.AutoSize := True;
      VendorText.Parent := VendorHostPage.Surface;

      VendorEdit := TNewEdit.Create(VendorHostPage);
      VendorEdit.Top := ScaleY(25);
      VendorEdit.Left := ScaleX(200);
      VendorEdit.Parent := VendorHostPage.Surface; 
      
    end;
    1:
    begin
      VendorText := TNewStaticText.Create(VendorHostPage);
      VendorText.Anchors := [akLeft, akRight, akBottom];
      VendorText.Caption := 'AssetTracking connects to RTLS server to recieve streaming location data';
      VendorText.AutoSize := True;
      VendorText.Parent := VendorHostPage.Surface;

      VendorText := TNewStaticText.Create(VendorHostPage);
      VendorText.Top := ScaleY(25);
      VendorText.Anchors := [akLeft, akRight, akBottom];
      VendorText.Caption := 'Centrak RTLS Server IP address:';
      VendorText.AutoSize := True;
      VendorText.Parent := VendorHostPage.Surface;

      VendorEdit := TNewEdit.Create(VendorHostPage);
      VendorEdit.Top := ScaleY(25);
      VendorEdit.Left := ScaleX(200);
      VendorEdit.Parent := VendorHostPage.Surface;
      
      VendorText := TNewStaticText.Create(VendorHostPage);
      VendorText.Top := ScaleY(50);
      VendorText.Anchors := [akLeft, akRight, akBottom];
      VendorText.Caption := 'Centrak RTLS Server port:';
      VendorText.AutoSize := True;
      VendorText.Parent := VendorHostPage.Surface;

      VendorEdit := TNewEdit.Create(VendorHostPage);
      VendorEdit.Top := ScaleY(50);
      VendorEdit.Left := ScaleX(200);
      VendorEdit.Parent := VendorHostPage.Surface;      
    end;
    2:
    begin
      VendorText := TNewStaticText.Create(VendorHostPage);
      VendorText.Anchors := [akLeft, akRight, akBottom];
      VendorText.Caption := 'AssetTracking connects to RTLS server to recieve streaming location data';
      VendorText.AutoSize := True;
      VendorText.Parent := VendorHostPage.Surface;

      VendorText := TNewStaticText.Create(VendorHostPage);
      VendorText.Top := ScaleY(25);
      VendorText.Anchors := [akLeft, akRight, akBottom];
      VendorText.Caption := 'Sonitor RTLS Server IP address:';
      VendorText.AutoSize := True;
      VendorText.Parent := VendorHostPage.Surface;

      VendorEdit := TNewEdit.Create(VendorHostPage);
      VendorEdit.Top := ScaleY(25);
      VendorEdit.Left := ScaleX(200);
      VendorEdit.Parent := VendorHostPage.Surface;
      
      VendorText := TNewStaticText.Create(VendorHostPage);
      VendorText.Top := ScaleY(50);
      VendorText.Anchors := [akLeft, akRight, akBottom];
      VendorText.Caption := 'Sonitor RTLS Events port:';
      VendorText.AutoSize := True;
      VendorText.Parent := VendorHostPage.Surface;

      VendorEdit := TNewEdit.Create(VendorHostPage);
      VendorEdit.Top := ScaleY(50);
      VendorEdit.Left := ScaleX(200);
      VendorEdit.Parent := VendorHostPage.Surface;   
           
      VendorText := TNewStaticText.Create(VendorHostPage);
      VendorText.Top := ScaleY(75);
      VendorText.Anchors := [akLeft, akRight, akBottom];
      VendorText.Caption := 'Sonitor RTLS API port:';
      VendorText.AutoSize := True;
      VendorText.Parent := VendorHostPage.Surface;

      VendorEdit := TNewEdit.Create(VendorHostPage);
      VendorEdit.Top := ScaleY(75);
      VendorEdit.Left := ScaleX(200);
      VendorEdit.Parent := VendorHostPage.Surface; 
    end;
  end;
end;

procedure InitializeWizard;
var
  InstallJava: Boolean;
  
begin
  VendorPage := CreateCustomPage(wpWelcome, 'RTLS HW Data Source Configuration', '');
  
  VendorText := TNewStaticText.Create(VendorPage);
  VendorText.Anchors := [akLeft, akRight, akBottom];
  VendorText.Caption := 'Please select the RTLS hardware vendor to install:';
  VendorText.AutoSize := True;
  VendorText.Parent := VendorPage.Surface;

  VendorText := TNewStaticText.Create(VendorPage);
  VendorText.Top := ScaleY(25);
  VendorText.Anchors := [akLeft, akRight, akBottom];
  VendorText.Caption := 'RTLS Vendor';
  VendorText.AutoSize := True;
  VendorText.Parent := VendorPage.Surface;

  ComboBox := TNewComboBox.Create(VendorPage);
  ComboBox.Top := ScaleY(25);
  ComboBox.Left := ScaleX(100);
  ComboBox.Anchors := [akLeft, akTop, akRight];
  ComboBox.Parent := VendorPage.Surface;
  ComboBox.Style := csDropDown;
  ComboBox.Items.Add('BBraun');
  ComboBox.Items.Add('Centrak');
  ComboBox.Items.Add('Sonitor');
  ComboBox.ItemIndex := 0;
  ComboBox.OnChange := @ComboBoxChange;

  VendorHostPage := CreateCustomPage(VendorPage.ID, 'RTLS HW Data Source Configuration', 'Provide Connection details to Teletracking RTLS');
  
  case ComboBox.ItemIndex of
    0:
    begin
      VendorText := TNewStaticText.Create(VendorHostPage);
      VendorText.Anchors := [akLeft, akRight, akBottom];
      VendorText.Caption := 'AssetTracking connects to the BBraun server to recieve the HL7 data';
      VendorText.AutoSize := True;
      VendorText.Parent := VendorHostPage.Surface;

      VendorText := TNewStaticText.Create(VendorHostPage);
      VendorText.Top := ScaleY(25);
      VendorText.Anchors := [akLeft, akRight, akBottom];
      VendorText.Caption := 'BBraun HL7 port:';
      VendorText.AutoSize := True;
      VendorText.Parent := VendorHostPage.Surface;

      VendorEdit := TNewEdit.Create(VendorHostPage);
      VendorEdit.Top := ScaleY(25);
      VendorEdit.Left := ScaleX(200);
      VendorEdit.Parent := VendorHostPage.Surface; 
    end;
  end;
 
end;

Expected behavior after selection combobox value:

BBraun behaviour Centrak behaviour Sonitor behaviour

PS: If you can't see the images on browser please download it, the code has written for first two screen ComboBox and Next screen based on selection not for rest of it.


Solution

  • Of course not. Assigning an object variable in Pascal Script does not destroy the object to which the variable was pointing to previously.

    You have to do that explicitly. Like:

    if Assigned(VendorText) then VendorText.Free;
    

    Though more common way to implement, what you want, would be to create the controls once at the beginning, hiding/showing and/or changing their caption, as the combo box selection changes. Such solution would require significantly less code.