ees
ees

Reputation: 335

In Inno Setup, is it possible to create a page that has an input file gadget inside radio buttons?

In Inno Setup, you can have a TInputFileWizardPage, with a nice file selection gadget. But can you put that same gadget on a generic TWizardPage? Specifically, I'd like have radio buttons such that when one particular choice is activated the file gadget is used.

Upvotes: 1

Views: 1492

Answers (1)

TLama
TLama

Reputation: 76693

Easier than building your own input file page is modifying the created TInputFileWizardPage page. The following example adds two radio buttons and shifts the input file item components. By default, the input file components are disabled, and the first radio button is selected. If the user selects the second radio button, the input file components are enabled:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Code]
var
  InputPage: TInputFileWizardPage;
  RadioButtons: array[0..1] of TNewRadioButton;

procedure ShiftFilePageItem(Page: TInputFileWizardPage; Index: Integer;
  Offset: Integer);
begin
  Page.Edits[Index].Top := Page.Edits[Index].Top + Offset;
  Page.Buttons[Index].Top := Page.Buttons[Index].Top + Offset;
  Page.PromptLabels[Index].Top := Page.PromptLabels[Index].Top + Offset;
end;

procedure SetFilePageItemEnabled(Page: TInputFileWizardPage; Index: Integer;
  Enabled: Boolean);
begin
  Page.Edits[Index].Enabled := Enabled;
  Page.Buttons[Index].Enabled := Enabled;
  Page.PromptLabels[Index].Enabled := Enabled;
end;

procedure RadioButtonClick(Sender: TObject);
begin
  SetFilePageItemEnabled(InputPage, 0, Sender = RadioButtons[1]);
end;

procedure InitializeWizard;
begin
  InputPage := CreateInputFilePage(wpWelcome, 'Caption', 'Description',
    'SubCaption');
  InputPage.Add('Prompt', 'All files|*.*', '*.*');

  RadioButtons[0] := TNewRadioButton.Create(InputPage);
  RadioButtons[0].Parent := InputPage.Surface;
  RadioButtons[0].Left := 0;
  RadioButtons[0].Top := 0;
  RadioButtons[0].Width := InputPage.SurfaceWidth;
  RadioButtons[0].Checked := True;
  RadioButtons[0].Caption := 'Option with no file selection';
  RadioButtons[0].OnClick := @RadioButtonClick;

  RadioButtons[1] := TNewRadioButton.Create(InputPage);
  RadioButtons[1].Parent := InputPage.Surface;
  RadioButtons[1].Left := RadioButtons[0].Left;
  RadioButtons[1].Top := RadioButtons[0].Top + RadioButtons[0].Height + 2;
  RadioButtons[1].Width := InputPage.SurfaceWidth;
  RadioButtons[1].Checked := False;
  RadioButtons[1].Caption := 'Option with file selection';
  RadioButtons[1].OnClick := @RadioButtonClick;

  ShiftFilePageItem(InputPage, 0, RadioButtons[1].Top);
  SetFilePageItemEnabled(InputPage, 0, False);
end;

This is how the page looks like by default:

enter image description here

Upvotes: 2

Related Questions