Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
792 views
in Technique[技术] by (71.8m points)

delphi - Inno Setup ComponentsList OnClick event

I have a list of components for my Inno Setup installer, 19 different options, I want to set the OnClick event for ONE of the components. Is there a way to do this? Or is there a way to check which component triggered the OnClick event if it's set for all components?

Currently, the OnClick event is set like so:

Wizardform.ComponentsList.OnClick := @CheckChange;

I would like to do something like:

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

The WizardForm.ComponentList is declared as a: TNewCheckListBox

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

1 Answer

0 votes
by (71.8m points)

You do not want to use OnClick, use OnClickCheck instead.

The OnClick is called for clicks which do not change checked state (like clicks outside of any item; or clicks on fixed items; or selection change using keyboard), but mainly it is not called for checks using keyboard.

The OnClickCheck is called only, when the checked state changes, and both for keyboard and mouse.

To tell which item was checked by user, use ItemIndex property. The user can check only the selected item.

Though if you have a components hierarchy, or setup types, the items checked automatically by the installer due to a change in child/parent items or change in the setup type, won't trigger the OnClickCheck (nor the OnClick). So to tell all changes, all you can do is to remember the previous state and compare it against the current state, when the WizardForm.ComponentsList.OnClickCheck or WizardForm.TypesCombo.OnChange are called.

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;

For a more generic solution, see Inno Setup Detect changed task/item in TasksList.OnClickCheck event. Though with components, one has to trigger the check on the WizardForm.TypesCombo.OnChange call too.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share
...