Inno Setup ComponentsList OnClick事件

时间:2016-05-02 18:41:02

标签: delphi inno-setup pascalscript

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

目前,OnClick事件设置如下:

Wizardform.ComponentsList.OnClick := @CheckChange;

我想做点什么:

Wizardform.ComponentsList.Items[x].OnClick := @DbCheckChange;

WizardForm.ComponentList声明为:TNewCheckListBox

2 个答案:

答案 0 :(得分:2)

您不想使用OnClick,而是使用OnClickChange

OnClick用于不更改已检查状态的点击(例如任何项目之外的点击;或点击固定项目;或使用键盘选择更改),但主要是不使用键盘检查

仅在检查状态发生变化时调用OnClickChange,并且键盘和鼠标都会调用。{/ p>

要告知用户选中了哪个项目,请使用ItemIndex属性。用户只能检查所选项目。

虽然如果您有组件层次结构或设置类型,但由于子/父项目的更改或设置类型的更改,安装程序会自动检查项目,但不会触发OnClickCheck (也不是OnClick)。所以,要告诉所有更改,您可以做的就是记住以前的状态,并在调用WizardForm.ComponentsList.OnClickCheckWizardForm.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电话的检查。

答案 1 :(得分:1)

  

或者有没有办法检查哪个组件触发了onclick事件,如果它是为所有组件设置的?

大多数组件事件都有Sender参数指向触发事件的组件对象。但是,在这种情况下,Sender可能是ComponentsList本身。根据{{​​1}}实际声明为(ComponentsList等)的内容,它可能有一个属性来指定当前正在选择/单击的项目(TListBox等)。或者它甚至可能有一个单独的事件来报告每个项目的点击次数。你没有说明ItemIndex被宣布为什么,所以没有人可以告诉你究竟在里面寻找什么。