Delphi Inno设置组件列表OnClick事件

Delphi Inno设置组件列表OnClick事件,delphi,inno-setup,pascalscript,Delphi,Inno Setup,Pascalscript,我有一个Inno安装程序的组件列表,19个不同的选项,我想为一个组件设置OnClick事件。有办法做到这一点吗?或者,如果为所有组件设置了OnClick事件,是否有方法检查哪个组件触发了该事件 当前,OnClick事件设置如下: Wizardform.ComponentsList.OnClick := @CheckChange; 我想做一些类似的事情: Wizardform.ComponentsList.Items[x].OnClick := @DbCheckChange; WizardFo

我有一个Inno安装程序的组件列表,19个不同的选项,我想为一个组件设置
OnClick
事件。有办法做到这一点吗?或者,如果为所有组件设置了
OnClick
事件,是否有方法检查哪个组件触发了该事件

当前,
OnClick
事件设置如下:

Wizardform.ComponentsList.OnClick := @CheckChange;
我想做一些类似的事情:

Wizardform.ComponentsList.Items[x].OnClick := @DbCheckChange;
WizardForm.ComponentList
声明为:
TNewCheckListBox

或者,如果为所有组件设置了onclick事件,是否有方法检查哪个组件触发了onclick事件


大多数组件事件都有一个
Sender
参数,用于指向触发事件的组件对象。但是,在这种情况下,
发送方
很可能是
组件列表
本身。根据
ComponentsList
实际声明的内容(
TListBox
等),它可能有一个属性来指定当前正在选择/单击的项目(
itemlindex
等)。或者它甚至可能有一个单独的事件来报告每项点击。您没有说明
组件列表
声明为什么,因此这里没有人能确切地告诉您要在列表中查找什么。

您不想使用
OnClick
,请改用
OnClickCheck

OnClick
用于不改变选中状态的单击(如任何项目外的单击;或固定项目上的单击;或使用键盘更改选择),但主要不用于使用键盘的检查

仅当选中状态更改时,才调用键盘和鼠标的
OnClickCheck

要知道用户检查了哪个项目,请使用
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;
const
Iteem=2;{您感兴趣的项目}
变量
PrevItemChecked:布尔值;
类型mboonchangeprov:TNotifyEvent;
程序组件列表检查更改;
变量
项目:字符串;
开始
如果PreviItemChecked WizardForm.ComponentsList.Checked[ItItem],则
开始
Item:=WizardForm.ComponentsList.ItemCaption[ItItem];
如果选中了WizardForm.ComponentsList
开始
日志(格式('%s“已选中,[Item]));
结束
其他的
开始
日志(格式(“%s”未选中,[Item]);
结束;
PreviItemChecked:=WizardForm.ComponentsList.Checked[ItItem];
结束;
结束;
程序组件列表点击检查(发送方:ToObject);
开始
组件检查更改;
结束;
程序类型mboonchange(发送方:TObject);
开始
{首先让Inno安装程序更新组件选择}
类型mboonchangeprov(发送方);
{然后检查更改}
组件检查更改;
结束;
过程初始化Wizard();
开始
WizardForm.ComponentList.OnClickCheck:=@ComponentsListClickCheck;
{Inno安装程序本身依赖于WizardForm.TypesCombo.OnChange,}
{所以我们必须保留它的处理程序。}
typescomboonchangeprov:=WizardForm.TypesCombo.OnChange;
WizardForm.TypesCombo.OnChange:=@TypesComboOnChange;
{记住初始状态}
{(现在已经根据}选择了组件)
{默认设置或以前的安装)}
PreviItemChecked:=WizardForm.ComponentsList.Checked[ItItem];
结束;


有关更通用的解决方案,请参阅。虽然使用组件,但也必须触发对
WizardForm.TypesCombo.OnChange调用的检查。

列表是一个
TNewCheckListBox