您不想使用OnClick
,請改爲使用OnClickChange
。
OnClick
被稱爲點擊,不會更改檢查狀態(如點擊任何項目外;點擊固定項目;或選擇更改使用鍵盤),但主要是它不被稱爲使用鍵盤檢查。
只有當選中的狀態發生變化時,纔會調用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
調用的檢查。
太棒了,非常感謝。 –