2016-05-02 171 views
2

我的组件列表我的Inno Setup的安装程序,19点不同的选择,我想设置OnClick事件的组件ONE。有没有办法做到这一点?或者是否有办法检查哪个组件设置了所有组件,从而触发了事件OnClickInno Setup的ComponentsList OnClick事件

目前,OnClick事件设置像这样:

Wizardform.ComponentsList.OnClick := @CheckChange; 

我想这样做:

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

WizardForm.ComponentList声明为:TNewCheckListBox

回答

2

您不想使用OnClick,请改为使用OnClickChange

OnClick被称为点击,不会更改检查状态(如点击任何项目外;点击固定项目;或选择更改使用键盘),但主要是它不被称为使用键盘检查。

只有当选中的状态发生变化时,才会调用OnClickChange,并且对于键盘和鼠标都是如此。

要知道用户检查了哪个项目,请使用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事件,如果它为所有comp设置的onents?

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

+0

该列表是一个'TNewCheckListBox' –