Home > Blockchain >  Inno Setup - Add 4 license pages
Inno Setup - Add 4 license pages

Time:11-01

I followed Martin's answer Next button enabled even when "I do not accept is selected". Also License 4 is coming before License 2

I know I have made a basic mistake somewhere when I tried to expand Martin's answer to cover additional licenses, but I couldn't figure it out yet.

Let me know if anyone has a idea to fix/debug this.

Thanks! a

CodePudding user response:

I'm not gonna try to fix your issues as the way you triplicated all the code is pretty inefficient and hard to maintain. Factor out the creation of the additional license pages instead. Something like this:

[Setup]
LicenseFile=license1.txt

[Files]
Source: "license2.txt"; Flags: dontcopy
Source: "license3.txt"; Flags: dontcopy
Source: "license4.txt"; Flags: dontcopy

[Code]

var
  LicenseAcceptedRadioButtons: array of TRadioButton;

procedure CheckLicenseAccepted(Sender: TObject);
begin
  // Update Next button when user (un)accepts the license
  WizardForm.NextButton.Enabled :=
    LicenseAcceptedRadioButtons[TComponent(Sender).Tag].Checked;
end;

procedure LicensePageActivate(Sender: TWizardPage);
begin
  // Update Next button when user gets to second license page
  CheckLicenseAccepted(LicenseAcceptedRadioButtons[Sender.Tag]);
end;

function CloneLicenseRadioButton(
  Page: TWizardPage; Source: TRadioButton): TRadioButton;
begin
  Result := TRadioButton.Create(WizardForm);
  Result.Parent := Page.Surface;
  Result.Caption := Source.Caption;
  Result.Left := Source.Left;
  Result.Top := Source.Top;
  Result.Width := Source.Width;
  Result.Height := Source.Height;
  // Needed for WizardStyle=modern / WizardResizable=yes
  Result.Anchors := Source.Anchors;
  Result.OnClick := @CheckLicenseAccepted;
  Result.Tag := Page.Tag;
end;

var
  LicenseAfterPage: Integer;

procedure AddLicensePage(LicenseFileName: string);
var
  Idx: Integer;
  Page: TOutputMsgMemoWizardPage;
  LicenseFilePath: string;
  RadioButton: TRadioButton;
begin
  Idx := GetArrayLength(LicenseAcceptedRadioButtons);
  SetArrayLength(LicenseAcceptedRadioButtons, Idx   1);

  Page :=
    CreateOutputMsgMemoPage(
      LicenseAfterPage, SetupMessage(msgWizardLicense),
      SetupMessage(msgLicenseLabel), SetupMessage(msgLicenseLabel3), '');
  Page.Tag := Idx;

  // Shrink license box to make space for radio buttons
  Page.RichEditViewer.Height := WizardForm.LicenseMemo.Height;
  Page.OnActivate := @LicensePageActivate;

  // Load license
  // Loading ex-post, as Lines.LoadFromFile supports UTF-8,
  // contrary to LoadStringFromFile.
  ExtractTemporaryFile(LicenseFileName);
  LicenseFilePath := ExpandConstant('{tmp}\'   LicenseFileName);
  Page.RichEditViewer.Lines.LoadFromFile(LicenseFilePath);
  DeleteFile(LicenseFilePath);

  // Clone accept/do not accept radio buttons
  RadioButton := CloneLicenseRadioButton(Page, WizardForm.LicenseAcceptedRadio);
  LicenseAcceptedRadioButtons[Idx] := RadioButton;

  RadioButton := CloneLicenseRadioButton(Page, WizardForm.LicenseNotAcceptedRadio);
  // Initially not accepted
  RadioButton.Checked := True;

  LicenseAfterPage := Page.ID;
end;

procedure InitializeWizard();
begin
  LicenseAfterPage := wpLicense;
  AddLicensePage('license2.txt');
  AddLicensePage('license3.txt');
  AddLicensePage('license4.txt');
end;

enter image description here

enter image description here

enter image description here

enter image description here

  • Related