您不想使用OnClick
,请改为使用OnClickChange
。
OnClick
被称为点击,不会更改检查状态(如点击任何项目外;点击固定项目;或选择更改使用键盘),但主要是它不被称为使用键盘检查。
只有当选中的状态发生变化时,才会调用OnClickChange
,并且对于键盘和鼠标都是如此。
要知道用户检查了哪个项目,请使用ItemIndex
属性。用户只能检查选择的项目。
虽然如果您有组件层次结构或安装类型,安装程序会自动检查由于子/父项目更改或安装类型更改而导致的项目,但不会触发OnClickCheck
(或OnClick
) 。因此,要告诉所有更改,只需调用WizardForm.ComponentsList.OnClickCheck
或WizardForm.TypesCombo.OnChange
即可记住以前的状态并将其与当前状态进行比较。
const
TheItem = 2; { the item you are interested in }
var
PrevItemChecked: Boolean;
TypesComboOnChangePrev: TNotifyEvent;
procedure ComponentsListCheckChanges;
var
Item: string;
begin
if PrevItemChecked <> WizardForm.ComponentsList.Checked[TheItem] then
begin
Item := WizardForm.ComponentsList.ItemCaption[TheItem];
if WizardForm.ComponentsList.Checked[TheItem] then
begin
Log(Format('"%s" checked', [Item]));
end
else
begin
Log(Format('"%s" unchecked', [Item]));
end;
PrevItemChecked := WizardForm.ComponentsList.Checked[TheItem];
end;
end;
procedure ComponentsListClickCheck(Sender: TObject);
begin
ComponentsListCheckChanges;
end;
procedure TypesComboOnChange(Sender: TObject);
begin
{ First let Inno Setup update the components selection }
TypesComboOnChangePrev(Sender);
{ And then check for changes }
ComponentsListCheckChanges;
end;
procedure InitializeWizard();
begin
WizardForm.ComponentsList.OnClickCheck := @ComponentsListClickCheck;
{ The Inno Setup itself relies on the WizardForm.TypesCombo.OnChange, }
{ so we have to preserve its handler. }
TypesComboOnChangePrev := WizardForm.TypesCombo.OnChange;
WizardForm.TypesCombo.OnChange := @TypesComboOnChange;
{ Remember the initial state }
{ (by now the components are already selected according to }
{ the defaults or the previous installation) }
PrevItemChecked := WizardForm.ComponentsList.Checked[TheItem];
end;
对于一个更通用的解决方案,请参阅Inno Setup Detect changed task/item in TasksList.OnClickCheck event。虽然有组件,但也必须触发WizardForm.TypesCombo.OnChange
调用的检查。
太棒了,非常感谢。 –