[lazarus] Bug: Setting checkbox.checked triggers onclick

Michael Van Canneyt michael.vancanneyt at wisa.be
Tue Mar 25 10:52:11 EST 2003

On Tue, 25 Mar 2003, Mattias Gaertner wrote:

> On Mon, 24 Mar 2003 09:28:05 +0100 (W. Europe Standard Time)
> Michael Van Canneyt <michael.vancanneyt at wisa.be> wrote:
> >
> >
> > On 23 Mar 2003, Tony Maro wrote:
> >
> > > It's not _supposed_ to do that is it?
> >
> > Let's say that it doesn't do that in Delphi.
> I just tried under Delphi 6: Yes it does. (changing TCustomCheckBox.Checked
> via program calls OnClick).

My apologies, you are right.

It is setting the ItemIndex of a TCombobox in code versus manually
choosing an item that doesn't trigger the 'onchange' event.
I believe there is also such an issue in TMenuItem. I would have to
check that.

It's all the same issue of course.

> > > I'm trying to detect when a user checks the box so I can enable a save
> > > button, but if I change from one record to another and programmatically
> > > set the .enabled property it triggers the onclick event for the
> > > checkbox.
> >
> > This is a good point, which depends actually on the toolkit used.
> > Personally, I think that the event 'OnClick' should be separated out in
> > 'OnClick' (clicked by user) and 'OnChange' (State of checkbox changed)
> > But this will give compatibility problems.
> I vote for this OnChange/OnClick separation.
> Should I add a boolean property 'UseOnChange'?

I think this is a good idea. It should be used consistently to separate
user events from state changing events.

> What should be the default?

Make a global var, which is used as default when creating a combobox.
The default value should maybe be 'False' for Delphi compatibility.


More information about the Lazarus mailing list