I have code which is used for custom installation using Inno Setup. In this I have two radio buttons on a custom page. If user selects the first radio button, it should show another custom page with user input text box and text to be save in file. If user select the other radio button, the other custom page should not show.
Here is my code
[Code]
var
FullRadioButton: TNewRadioButton;
PartRadioButton: TNewRadioButton;
CustomPage: TWizardPage;
UserInputsPage: TInputQueryWizardPage;
FullDescLabel: TLabel;
PartDescLabel: TLabel;
url: String;
const
FullDescText ='Full Installation.';
PartDescText ='Partial Installation.';
procedure InitializeWizard;
begin
CustomPage := CreateCustomPage(wpWelcome, 'Installation type', '');
FullRadioButton := TNewRadioButton.Create(WizardForm);
FullRadioButton.Parent := CustomPage.Surface;
FullRadioButton.Top := 16;
FullRadioButton.Width := CustomPage.SurfaceWidth;
FullRadioButton.Font.Style := [fsBold];
FullRadioButton.Font.Size := 9;
FullRadioButton.Caption := 'Default Installation'
FullDescLabel := TLabel.Create(WizardForm);
FullDescLabel.Parent := CustomPage.Surface;
FullRadioButton.Checked := True;
FullDescLabel.Left := 8;
FullDescLabel.Top := FullRadioButton.Top + FullRadioButton.Height + 8;
FullDescLabel.Width := CustomPage.SurfaceWidth;
FullDescLabel.Height := 40;
FullDescLabel.AutoSize := False;
FullDescLabel.Wordwrap := True;
FullDescLabel.Caption := FullDescText;
PartRadioButton := TNewRadioButton.Create(WizardForm);
PartRadioButton.Parent := CustomPage.Surface;
//PartRadioButton.Checked := True
PartRadioButton.Top := FullDescLabel.Top + FullDescLabel.Height + 16;
PartRadioButton.Width := CustomPage.SurfaceWidth;
PartRadioButton.Font.Style := [fsBold];
PartRadioButton.Font.Size := 9;
PartRadioButton.Caption := 'Custom Installation'
PartDescLabel := TLabel.Create(WizardForm);
PartDescLabel.Parent := CustomPage.Surface;
PartDescLabel.Left := 8;
PartDescLabel.Top := PartRadioButton.Top + PartRadioButton.Height + 8;
PartDescLabel.Width := CustomPage.SurfaceWidth;
PartDescLabel.Height := 40;
PartDescLabel.AutoSize := False;
PartDescLabel.Wordwrap := True;
PartDescLabel.Caption := PartDescText;
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
if (PartRadioButton.Checked) then
UserInputsPage := CreateInputQueryPage(wpWelcome,
'Url information', 'Url',
'Please specify the following informat, then click Next.');
UserInputsPage.Add('URL:', False);
UserInputsPage.Values[0] := ExpandConstant('');
if(CurPageID = UserInputsPage.ID) then;
begin
url := UserInputsPage.Values[0];
SaveStringToFile('path', 'user_input='+'"'+url+'"'+#13#10,True);
end;
Result := True;
end;
Please help me out
Thanks in advance!
Use TWizardPage.OnShouldSkipPage
event (or ShouldSkipPage
event function) to conditionally skip your custom page.
The custom page should better also be created (unconditionally) in the InitializeWizard
, not in the NextButtonClick
(the NextButtonClick
can be called multiple times for the same page, if the user returns back).
Additionally, the UserInputsPage
must show after the CustomPage
. While you are currently constructing it to show before. For that, pass CustomPage.ID
as the first argument of the CreateInputQueryPage
.
function UserInputsPageShouldSkipPage(Sender: TWizardPage): Boolean;
begin
Result := not PartRadioButton.Checked;
end;
UserInputsPage :=
CreateInputQueryPage(
CustomPage.ID, 'Url information', 'Url',
'Please specify the following informat, then click Next.');
// ...
UserInputsPage.OnShouldSkipPage := @UserInputsPageShouldSkipPage;
Similar questions:
Also, you should not do any changes to the user's system, before the user confirms the installation. So typically, you do not want call SaveStringToFile
when user click Next on the custom page (not to mention again that it can happen multiple times, if user returns back). Better use CurStepChanged
for ssInstall
or ssPostInstall
step.
And your NextButtonClick
code is wrong anyway, due to the semicolon after the then
. Effectively you call SaveStringToFile
on each and every page of the wizard.