在Inno Setup中更改ComboBox后在下一个屏幕上动态显示控件和内容?

问题描述

当我第一次运行此代码时,一切都会按预期进行。但是一旦选择Sonitor然后选择BBraunSonitor控件(标签和文本框)就不会消失,它们仍在屏幕上。

[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,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,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,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,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,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,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,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,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,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,'Provide Connection details to Teletracking RTLS');
  
  case ComboBox.ItemIndex of
    0:
    begin
      vendorText := TNewStaticText.Create(vendorHostPage);
      vendorText.Anchors := [akLeft,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;

选择组合框值后的预期行为:

BBraun behaviour

Centrak behaviour

Sonitor behaviour

PS:如果无法在浏览器中看到图像,请下载该图像,该代码已根据选择的前两个屏幕ComboBox和下一个屏幕编写,而不是其余部分。

解决方法

当然不是。在Pascal脚本中分配对象变量不会破坏该变量先前指向的对象。

您必须明确地执行此操作。喜欢:

if Assigned(VendorText) then VendorText.Free;

尽管更常见的实现方式是,您希望的是在开始时一次创建控件,随着组合框选择的更改隐藏/显示和/或更改其标题。这样的解决方案将需要更少的代码。