2016-05-02 183 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' –