我有一个Inno Setup安装程序的组件列表,19个不同的选项,我想为其中一个组件设置OnClick事件.有没有办法做到这一点?或者有没有办法检查哪个组件触发了OnClick事件,如果它是为所有组件设置的?
目前,OnClick事件设置如下:
Wizardform.ComponentsList.OnClick := @CheckChange;
我想做的事情如下:
Wizardform.ComponentsList.Items[x].OnClick := @DbCheckChange;
WizardForm.ComponentList声明为:TNewCheckListBox
解决方法
您不想使用OnClick,而是使用OnClickChange.
OnClick被调用用于不改变已检查状态的点击(例如任何项目之外的点击;或点击固定项目;或使用键盘进行选择更改),但主要是不使用键盘进行检查.
仅当选中状态更改时,才会调用OnClickChange,键盘和鼠标都会调用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调用的检查.