1

Why don't rbStandardInstallType and rbCustomInstallType radio buttons get checked even though I set the Checked property of one of those to True? On the other hand, rbDefaultMSSQLInstance and rbNamedMSSQLInstance radio buttons do get checked.

I create radio buttons like this:

function CreateRadioButton(
  AParent: TNewNotebookPage; AChecked: Boolean; AWidth, ALeft, ATop, AFontSize: Integer;
  AFontStyle: TFontStyles; const ACaption: String): TNewRadioButton;
begin
  Result := TNewRadioButton.Create(WizardForm);
  with Result do
    begin
      Parent := AParent;
      Checked := AChecked;
      Width := AWidth;
      Left := ALeft;
      Top := ATop;
      Font.Size := AFontSize;
      Font.Style := AFontStyle;
      Caption := ACaption;
    end;
end;

I have 2 custom pages where I must show my image on the left and some text and radio buttons on the right (2 radio buttons per page). So, in my InitializeWizard procedure I've written this:

wpSelectInstallTypePage := CreateCustomPage(wpSelectDir, 'Caption', 'Description');
rbStandardInstallType := CreateRadioButton(WizardForm.InnerPage, True, WizardForm.InnerPage.Width, ScaleX(15), WizardForm.MainPanel.Top + ScaleY(30), 9, [fsBold], 'Standard');
rbCustomInstallType := CreateRadioButton(WizardForm.InnerPage, False, rbStandardInstallType.Width, rbStandardInstallType.Left, rbStandardInstallType.Top + rbStandardInstallType .Height + ScaleY(16), 9, [fsBold], 'Custom');

wpMSSQLInstallTypePage := CreateCustomPage(wpSelectInstallTypePage.ID, 'Caption2', 'Description2');
rbDefaultMSSQLInstance := CreateRadioButton(WizardForm.InnerPage, True, WizardForm.InnerPage.Width, ScaleX(15), WizardForm.MainPanel.Top + ScaleY(30), 9, [fsBold], 'DefaultInstance');
rbNamedMSSQLInstance := CreateRadioButton(WizardForm.InnerPage, False, rbDefaultMSSQLInstance.Width, rbDefaultMSSQLInstance.Left, rbDefaultMSSQLInstance.Top + rbDefaultMSSQLInstance.Height + ScaleY(10), 9, [fsBold], 'NamedInstance');

And finally, here's my CurPageChanged code in order to display all the controls properly:

procedure CurPageChanged(CurPageID: Integer);
  begin
    case CurPageID of
      wpSelectInstallTypePage.ID, wpMSSQLInstallTypePage.ID:
          WizardForm.InnerNotebook.Visible := False;  
    else
      WizardForm.InnerNotebook.Visible := True;
    end;
    rbDefaultMSSQLInstance.Visible := CurPageID = wpMSSQLInstallTypePage.ID;
    rbNamedMSSQLInstance.Visible := CurPageID = wpMSSQLInstallTypePage.ID;
    rbStandardInstallType.Visible := CurPageID = wpSelectInstallTypePage.ID;
    rbCustomInstallType.Visible := CurPageID = wpSelectInstallTypePage.ID;
  end
Martin Prikryl
  • 167,268
  • 50
  • 405
  • 846
JConstantine
  • 930
  • 4
  • 14

1 Answers1

0

You are adding the radio buttons to a wrong parent control (WizardForm.InnerPage). Not to the custom pages you are creating. And you then workaround that flaw by explicitly hiding/showing the radio buttons in CurPageChanged.

As all four radio buttons have the same parent (WizardForm.InnerPage), only one of them can be checked. So when you check the rbDefaultMSSQLInstance, the rbStandardInstallType is implicitly unchecked.


For the correct code, see:
Inno Setup Placing image/control on custom page

(make sure you remove your redundant CurPageChanged code)


You should also consider using CreateInputOptionPage instead of manually adding the radio buttons to a generic custom page.

Martin Prikryl
  • 167,268
  • 50
  • 405
  • 846
  • I was writing my code depending on this example: [link](https://stackoverflow.com/questions/11142870/how-to-hide-the-main-panel-and-show-an-image-over-the-whole-page) If I use `CreateInputOptionPage` how will I place my image on the very left then? `Left=0` by default is not what I need. That's why I used the `InnerPage`. – JConstantine Apr 16 '20 at 08:01
  • Had you shared the link with your question at the very beginning, the question would make much more sense. – Martin Prikryl Apr 16 '20 at 08:24
  • Anyway, I do not see what does the image have to do with this radio buttons question. It should probably go to a separate question. Though in general, you can keep your `CurPageChanged` hack for the image, even if you use the `CreateInputOptionPage` for the radio buttons. – Martin Prikryl Apr 16 '20 at 08:25
  • I've added the screenshot to my question. I don't know how can I make a page look like that without creating the custom page. Also, I add some text below those radio buttons as the detailed description. – JConstantine Apr 16 '20 at 08:27
  • The page created by `CreateInputOptionPage` can be customized the same way as the generic page created by `CreateCustomPage`. If you need details, please ask a new question. I believe that this question about radio buttons is answered. – Martin Prikryl Apr 16 '20 at 08:33