【问题标题】:Add 4 license pages in Inno Setup在 Inno Setup 中添加 4 个许可证页面
【发布时间】:2022-11-02 14:14:59
【问题描述】:

我按照 Martin 的回答 here 在我的 Inno Setup 安装程序中为 4 个许可证页面创建 UI。

代码如下所示(正在进行中..)

[Files]
Source: "license2_english.txt"; Flags: dontcopy
Source: "license3_english.txt"; Flags: dontcopy
Source: "license4_english.txt"; Flags: dontcopy

[Code]

var 
  SecondLicensePage: TOutputMsgMemoWizardPage;
  License2AcceptedRadio: TRadioButton;
  License2NotAcceptedRadio: TRadioButton;

  ThirdLicensePage: TOutputMsgMemoWizardPage;
  License3AcceptedRadio: TRadioButton;
  License3NotAcceptedRadio: TRadioButton;

  FourthLicensePage: TOutputMsgMemoWizardPage;
  License4AcceptedRadio: TRadioButton;
  License4NotAcceptedRadio: TRadioButton;

procedure CheckLicense2Accepted(Sender: TObject);
begin
  // Update Next button when user (un)accepts the license
  WizardForm.NextButton.Enabled := License2AcceptedRadio.Checked;
end;

procedure CheckLicense3Accepted(Sender: TObject);
begin
  // Update Next button when user (un)accepts the license
  WizardForm.NextButton.Enabled := License3AcceptedRadio.Checked;
end;

procedure CheckLicense4Accepted(Sender: TObject);
begin
  // Update Next button when user (un)accepts the license
  WizardForm.NextButton.Enabled := License4AcceptedRadio.Checked;
end;

function CloneLicenseRadioButtonL2(Source: TRadioButton): TRadioButton;
begin
  Result := TRadioButton.Create(WizardForm);
  Result.Parent := SecondLicensePage.Surface;
  Result.Caption := Source.Caption;
  Result.Left := Source.Left;
  Result.Top := Source.Top;
  Result.Width := Source.Width;
  Result.Height := Source.Height;
  Result.Anchors := Source.Anchors;
  Result.OnClick := @CheckLicense2Accepted;
end;

function CloneLicenseRadioButtonL3(Source: TRadioButton): TRadioButton;
begin
  Result := TRadioButton.Create(WizardForm);
  Result.Parent := ThirdLicensePage.Surface;
  Result.Caption := Source.Caption;
  Result.Left := Source.Left;
  Result.Top := Source.Top;
  Result.Width := Source.Width;
  Result.Height := Source.Height;
  Result.Anchors := Source.Anchors;
  Result.OnClick := @CheckLicense3Accepted;
end;

function CloneLicenseRadioButtonL4(Source: TRadioButton): TRadioButton;
begin
  Result := TRadioButton.Create(WizardForm);
  Result.Parent := FourthLicensePage.Surface;
  Result.Caption := Source.Caption;
  Result.Left := Source.Left;
  Result.Top := Source.Top;
  Result.Width := Source.Width;
  Result.Height := Source.Height;
  Result.Anchors := Source.Anchors;
  Result.OnClick := @CheckLicense4Accepted;
end;

//Create license wizards
procedure InitializeWizard();
var
  LicenseFileNameL2: string;
  LicenseFileNameL3: string;
  LicenseFilenameL4: string;
                 
  LicenseFilePathL2: string;
  LicenseFilePathL3: string;
  LicenseFilePathL4: string;
begin
  Log(Format('Temp :  %s', [ExpandConstant('{tmp}')]));
  // Create second license page, with the same labels as the original license page
  SecondLicensePage :=
    CreateOutputMsgMemoPage(
      wpLicense, SetupMessage(msgWizardLicense), SetupMessage(msgLicenseLabel),
      SetupMessage(msgLicenseLabel3), '');

  // Create third license page, with the same labels as the original license page
  ThirdLicensePage :=
    CreateOutputMsgMemoPage(
      wpLicense, SetupMessage(msgWizardLicense), SetupMessage(msgLicenseLabel),
      SetupMessage(msgLicenseLabel3), '');

  FourthLicensePage :=
    CreateOutputMsgMemoPage(
      wpLicense, SetupMessage(msgWizardLicense), SetupMessage(msgLicenseLabel),
      SetupMessage(msgLicenseLabel3), '');

  // Shrink license box to make space for radio buttons
  SecondLicensePage.RichEditViewer.Height := WizardForm.LicenseMemo.Height;
  ThirdLicensePage.RichEditViewer.Height  := WizardForm.LicenseMemo.Height;
  FourthLicensePage.RichEditViewer.Height := WizardForm.LicenseMemo.Height;

  // Load license
  // Loading ex-post, as Lines.LoadFromFile supports UTF-8,
  // contrary to LoadStringFromFile.
  LicenseFileNameL2 := 'license2_english.txt';
  LicenseFileNameL3 := 'license3_english.txt';
  LicenseFileNameL4 := 'license4_english.txt';

  LicenseFilePathL2 := ExpandConstant('{tmp}\' + LicenseFileNameL2);
  LicenseFilePathL3 := ExpandConstant('{tmp}\' + LicenseFileNameL3);
  LicenseFilePathL4 := ExpandConstant('{tmp}\' + LicenseFileNameL4);

  ExtractTemporaryFile(LicenseFileNameL2);
  ExtractTemporaryFile(LicenseFileNameL3);
  ExtractTemporaryFile(LicenseFileNameL4);

  SecondLicensePage.RichEditViewer.Lines.LoadFromFile(LicenseFilePathL2);
  ThirdLicensePage.RichEditViewer.Lines.LoadFromFile(LicenseFilePathL3);
  FourthLicensePage.RichEditViewer.Lines.LoadFromFile(LicenseFilePathL4);

  DeleteFile(LicenseFilePathL2);
  DeleteFile(LicenseFilePathL3);
  DeleteFile(LicenseFilePathL4);


  // Clone accept/do not accept radio buttons for the second license
  License2AcceptedRadio :=
    CloneLicenseRadioButtonL2(WizardForm.LicenseAcceptedRadio);
  License2NotAcceptedRadio :=
    CloneLicenseRadioButtonL2(WizardForm.LicenseNotAcceptedRadio);

  License3AcceptedRadio :=
    CloneLicenseRadioButtonL3(WizardForm.LicenseAcceptedRadio);
  License3NotAcceptedRadio :=
    CloneLicenseRadioButtonL3(WizardForm.LicenseNotAcceptedRadio);

  License4AcceptedRadio :=
    CloneLicenseRadioButtonL4(WizardForm.LicenseAcceptedRadio);
  License4NotAcceptedRadio :=
    CloneLicenseRadioButtonL4(WizardForm.LicenseNotAcceptedRadio);


  // Initially not accepted
  License2NotAcceptedRadio.Checked := True;
  License3NotAcceptedRadio.Checked := True;
  License4NotAcceptedRadio.Checked := True;
end;

procedure CurPageChanged(CurPageID: Integer);
begin
  // Update Next button when user gets to second license page
  if CurPageID = SecondLicensePage.ID then
  begin
    CheckLicense2Accepted(nil);
  end;
end;

procedure CurPageChangedL3(CurPageID: Integer);
begin
  // Update Next button when user gets to second license page
  if CurPageID = ThirdLicensePage.ID then
  begin
    CheckLicense3Accepted(nil);
  end;
end;

procedure CurPageChangedL4(CurPageID: Integer);
begin
  // Update Next button when user gets to second license page
  if CurPageID = FourthLicensePage.ID then
  begin
    CheckLicense4Accepted(nil);
  end;
end;

使用此代码,我看到以下问题:

  1. 许可证 4 页面出现在许可证 2 和 3 之前
  2. 在第 2 页中,单选按钮最初初始化为“我不接受”。在这种情况下,“下一步”按钮被启用,用户可以移动到下一个屏幕。

    图像显示即使选择了“我不接受”也启用了下一步按钮。许可证 4 也将在许可证 2 之前出现

    我知道当我试图扩展马丁的答案以涵盖其他许可证时,我在某个地方犯了一个基本错误,但我还没有弄清楚。

    让我知道是否有人有解决/调试此问题的想法。

    谢谢! 一个

【问题讨论】:

  • UX 问题:有多个对话框需要用户接受其他许可协议将被推迟。做一个单身的对话框,告诉用户他必须接受所有列出的许可协议才能继续,然后列出它们以及打开记事本或浏览器或其他东西以查看许可的链接。

标签: user-interface inno-setup pascalscript


【解决方案1】:

我不会尝试解决您的问题,因为您将所有代码重复三次的方式非常低效且难以维护。而是考虑创建其他许可证页面。像这样的东西:

[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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-08
    相关资源
    最近更新 更多