如何在[运行]部分只允许一个复选框?

时间:2016-02-21 18:03:24

标签: inno-setup

我的Inno安装程序在安装过程中安装了三个程序。

我添加了三个程序中每个程序的复选框,以便在[Run]部分的安装页面后显示:

Filename: "{app}\Program1.exe"; Description: "{cm:LaunchProgram,{#StringChange("Program1", '&', '&&')}}"; Flags: nowait postinstall skipifsilent unchecked runascurrentuser;
Filename: "{app}\Program2.exe"; Description: "{cm:LaunchProgram,{#StringChange("Program2", '&', '&&')}}"; Flags: nowait postinstall skipifsilent unchecked runascurrentuser;
Filename: "{app}\Program3.exe"; Description: "{cm:LaunchProgram,{#StringChange("Program3", '&', '&&')}}"; Flags: nowait postinstall skipifsilent unchecked runascurrentuser;

如何让它只允许一次检查一个方框?

谢谢

1 个答案:

答案 0 :(得分:2)

您有以下选择:

将复选框转到单选按钮

[Code]

var
  RunListModified: Boolean;

procedure CurPageChanged(CurPageID: Integer);
var
  I: Integer;
begin
  { The first time the Finished page shows, turn all checkboxes to radio buttons. }
  { (note that the Finished page can show multiple times, }
  { if the InfoAfterFile directive is set only, }
  { or if there is some custom page before the Finished page) }
  if (CurPageID = wpFinished) and (not RunListModified) then
  begin
    { Add a dummy "Run nothing" entry }
    WizardForm.RunList.AddRadioButton('Run nothing', '', 0, True, True, -1);

    for I := 0 to WizardForm.RunList.Items.Count - 2 do
    begin
      { For all entries - take the first checkbox in the list, clone it to the end }
      { as a radio button with the same properties (mainly the caption and the object, }
      { which is actually index to the run list). }
      { Note that the ItemSubItem is always empty, ItemLevel always 0 and ItemEnabled }
      { always True. }
      WizardForm.RunList.AddRadioButton(
        WizardForm.RunList.ItemCaption[0],
        WizardForm.RunList.ItemSubItem[0],
        WizardForm.RunList.ItemLevel[0],
        False,
        WizardForm.RunList.ItemEnabled[0],
        WizardForm.RunList.ItemObject[0]);

      { And delete the original checkbox, pulling the next on to the first place }
      { for the next round. }
      WizardForm.RunList.Items.Delete(0);
    end;

    RunListModified := True;
  end;
end;

function NextButtonClick(CurPageID: Integer): Boolean;
begin
  if CurPageID = wpFinished then
  begin
    { Make sure we remove the dummy "Run nothing" entry, otherwise the Inno Setup fails }
    { processing it. }
    { The test for RunList.Count is for a case that a restart is needed and the RunList }
    { is never populated/shown. }
    { The test for ItemObject is here only in case we ever get here multiple time. }
    { But it should not really happen. }
    if (WizardForm.RunList.Items.Count > 0) and
       (Integer(WizardForm.RunList.ItemObject[0]) = -1) then
    begin
      WizardForm.RunList.Items.Delete(0);
    end;
  end;

  Result := True;
end;

enter image description here

以编程方式确保选中一个复选框后,其他所有复选框都将取消选中

[Code]

var
  RunListLastChecked: Integer;

procedure RunListClickCheck(Sender: TObject);
var
  I: Integer;
  Checked: Integer;
begin
  { Find if some other checkbox got checked }
  Checked := -1;
  for I := 0 to WizardForm.RunList.Items.Count - 1 do
  begin
    if WizardForm.RunList.Checked[I] and (I <> RunListLastChecked) then
    begin
      Checked := I;
    end;
  end;

  { If it was, uncheck the previously checked box and remember the new one }
  if Checked >= 0 then
  begin
    if RunListLastChecked >= 0 then
    begin
      WizardForm.RunList.Checked[RunListLastChecked] := False;
    end;

    RunListLastChecked := Checked;
  end;

  { Or if the previously checked box got unchecked, forget it. }
  { (This is not really necessary, it's just to clean the things up) }
  if (RunListLastChecked >= 0) and
     (not WizardForm.RunList.Checked[RunListLastChecked]) then
  begin
    RunListLastChecked := -1;
  end;
end;

procedure InitializeWizard();
begin
  WizardForm.RunList.OnClickCheck := @RunListClickCheck;
  RunListLastChecked := -1;
end;