如何在[运行]部分中仅允许一个复选框? [英] How to allow only one checked box in [Run] section?

查看:41
本文介绍了如何在[运行]部分中仅允许一个复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Inno Setup程序在安装过程中会安装三个程序.

我在 [运行] 部分的安装页面中添加了三个程序的复选框:

 文件名:"{app} \ Program1.exe";说明:"{cm:LaunchProgram,{#StringChange("Program1",'&','&&')}}";标志:nowait postinstall skipifsilent未经检查的runascurrentuser;文件名:"{app} \ Program2.exe";说明:"{cm:LaunchProgram,{#StringChange("Program2",'&','&&')}}";标志:nowait postinstall skipifsilent未经检查的runascurrentuser;文件名:"{app} \ Program3.exe";说明:"{cm:LaunchProgram,{#StringChange("Program3",'&','&&')}}";标志:nowait postinstall skipifsilent未经检查的runascurrentuser; 

如何使其只能一次选中一个框?

谢谢

解决方案

您有以下选择:

  • 将复选框转到单选按钮(此解决方案如下所示).

  • 以编程方式确保选中一个复选框时,所有其他复选框都未选中(此解决方案也在下面显示)

    对于类似的问题,另请参见

    有关类似问题,请参见将运行任务显示为单选而不是复选框吗?


    以编程方式确保选中一个复选框时,所有其他选项键都不会选中

     <代码> [代码]变种RunListLastChecked:整数;过程RunListClickCheck(Sender:TObject);变种I:整数;已检查:整数;开始{查找是否选中了其他复选框}检查:= -1;对于I:= 0到WizardForm.RunList.Items.Count-1开始如果WizardForm.RunList.Checked [I]和(I<> RunListLastChecked),则开始检查:=我;结尾;结尾;{如果是,请取消勾选先前的核取方块,并记住新的核取方块}如果Checked> = 0,则开始如果RunListLastChecked> = 0,则开始WizardForm.RunList.Checked [RunListLastChecked]:= False;结尾;RunListLastChecked:=已检查;结尾;{或者,如果以前选中的框未选中,则将其忘记.}{(这不是真正必要的,它只是用来清理东西)}如果(RunListLastChecked> = 0)并且(而不是WizardForm.RunList.Checked [RunListLastChecked]),然后开始RunListLastChecked:= -1;结尾;结尾;过程InitializeWizard();开始WizardForm.RunList.OnClickCheck:= @RunListClickCheck;RunListLastChecked:= -1;结尾; 

    My Inno Setup program installs three programs during the installation.

    I added the checkbox for each of the three programs to show after installation page in the [Run] section:

    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;
    

    How can I make it only allow to check one box at time?

    Thank you

    解决方案

    You have these options:


    Turning the checkboxes to radio buttons

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

    For a similar question, see Showing run tasks as radio choices instead of check boxes?


    Programmatically make sure that when one checkbox is checked, all others get unchecked

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

    这篇关于如何在[运行]部分中仅允许一个复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆