Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
638 views
in Technique[技术] by (71.8m points)

inno setup - TInputDirWizardPage with Radio Buttons

I need a setup page with two radio buttons. Clicking the second button should enable an input to define a path (Like it's done in TInputDirWizardPage).

Is it possible to customize TInputDirWizardPage for my needs?

Or do I need to build a CustomPage and define the controls by myself? If the second question will be answered with yes, how am I able to use the "directory input" (from the TInputDirWizardPage), or is it also neccessary to build this on my own?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As you correctly guessed you have several options:

  1. Start with TWizardPage and build everything from scratch
  2. Start with TInputDirWizardPage and add the radio buttons
  3. Start with TInputOptionWizardPage and add the edit box

The second option probably involves least customization. Though it needs a hack from Is it possible to allow a user to skip a TInputDirWizardPage in Inno Setup?

{ WORKAROUND }
{ Checkboxes and Radio buttons created on runtime do }
{ not scale their height automatically. }
{ See https://stackoverflow.com/q/30469660/850848 }
procedure ScaleFixedHeightControl(Control: TButtonControl);
begin
  Control.Height := ScaleY(Control.Height);
end;

var
  Page: TInputDirWizardPage;
  DefaultLocationButton: TRadioButton;
  CustomLocationButton: TRadioButton;
  OldNextButtonOnClick: TNotifyEvent;

procedure LocationButtonClick(Sender: TObject);
begin
  Page.Edits[0].Enabled := CustomLocationButton.Checked;
  Page.Buttons[0].Enabled := CustomLocationButton.Checked;
end;

procedure NextButtonOnClick(Sender: TObject);
var
  PrevDir: string;
begin
  { Do not validate, when "default location" is selected }
  if (WizardForm.CurPageID = Page.ID) and DefaultLocationButton.Checked then
  begin
    PrevDir := Page.Values[0];
    Page.Values[0] := GetWinDir; { Force value to pass validation }
    OldNextButtonOnClick(Sender);
    Page.Values[0] := PrevDir;
  end
    else
  begin
    OldNextButtonOnClick(Sender);
  end;
end;

procedure InitializeWizard();
begin
  Page := CreateInputDirPage(
    wpWelcome,
    'Select Personal Data Location', 'Where should personal data files be stored?',
    '', False, 'New Folder');
  Page.Add('');

  DefaultLocationButton := TRadioButton.Create(WizardForm);
  DefaultLocationButton.Parent := Page.Surface;
  DefaultLocationButton.Top := Page.Edits[0].Top;
  DefaultLocationButton.Caption := 'Use default location';
  DefaultLocationButton.Checked := True;
  DefaultLocationButton.OnClick := @LocationButtonClick;
  ScaleFixedHeightControl(DefaultLocationButton);
  
  CustomLocationButton := TRadioButton.Create(WizardForm);
  CustomLocationButton.Parent := Page.Surface;
  CustomLocationButton.Top :=
    DefaultLocationButton.Top + DefaultLocationButton.Height + ScaleY(8);
  CustomLocationButton.Caption := 'Use custom location';
  CustomLocationButton.OnClick := @LocationButtonClick;
  ScaleFixedHeightControl(DefaultLocationButton);

  Page.Buttons[0].Top :=
    Page.Buttons[0].Top +
    ((CustomLocationButton.Top + CustomLocationButton.Height + ScaleY(8)) -
      Page.Edits[0].Top);
  Page.Edits[0].Top :=
    CustomLocationButton.Top + CustomLocationButton.Height + ScaleY(8);
  Page.Edits[0].Left := Page.Edits[0].Left + ScaleX(16);
  Page.Edits[0].Width := Page.Edits[0].Width - ScaleX(16);
  Page.Edits[0].TabOrder := CustomLocationButton.TabOrder + 1;
  Page.Buttons[0].TabOrder := Page.Edits[0].TabOrder + 1;

  LocationButtonClick(nil); { Update edit for initial state of buttons }

  OldNextButtonOnClick := WizardForm.NextButton.OnClick;
  WizardForm.NextButton.OnClick := @NextButtonOnClick;
end;

enter image description here

enter image description here


More general question on the topic: Inno Setup Placing image/control on custom page.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...