我的 Inno Setup 程序在安装过程中安装了三个程序。
我在 [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;
如何让它一次只允许选中一个框?
谢谢
最佳答案
您有以下选择:
将复选框变为单选按钮(此解决方案如下所示)。
以编程方式确保选中一个复选框时,将取消选中所有其他复选框(此解决方案也在下面显示)
对于类似的问题,另请参阅 Inno Setup - Show children component as sibling and show check instead of square in checkbox .
使用
Tasks
带有exclusive
flag 的条目触发Run
没有 thepostinstall
flag 的条目(而不是由带有postinstall
标志的Run
条目创建的复选框)。
将复选框变成单选按钮
[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;
对于类似的问题,请参阅 Showing run tasks as radio choices instead of check boxes?
以编程方式确保当一个复选框被选中时,所有其他复选框都被取消选中
[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;
关于inno-setup - 如何在 [Run] 部分只允许一个复选框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35539827/