Board index » cppbuilder » CheckBox OnClick Event

CheckBox OnClick Event

Why does the line
MyCheckBox->Checked = true;
trigger the OnClick event of that checkbox?  I didn't think just
changing the value of the property by code would trigger the event
handler!

In contrast the line
MySpeedButton->Down = true
does not trigger the OnClick event.

In either case, shouldn't it at least be consistent?

--
Thanks

Oliver

If you would like to provide phone/e-mail support consulting to my
company send your qualifications to j...@{*word*2}software.com.

To reply to this post by e-mail, remove the "no-spam" from my e-mail
address.

 

Re:CheckBox OnClick Event


Because it does.

And it even says in the documentation that it does this:

TControl::OnClick

Usually OnClick occurs because the user presses and releases the primary
mouse button with the mouse pointer over the control. This event can also
occur when

The user selects an item in a grid, outline, list, or combo box by pressing
an arrow key.

The user presses Spacebar while a button or check box has focus.

The user presses Enter when the active form has a default button (specified
by the Default property).

The user presses Esc when the active form has a cancel button (specified by
the Cancel property).

The user presses the accelerator key for a button or check box. For example,
if the value of the Caption property of a check box is '&Bold', the B is
underlined at runtime and the OnClick event of the check box is triggered
when the user presses Alt+B.

The Checked property of a radio button is set to true.

*** The value of the Checked property of a check box is changed.

The Click method of a menu item is called.

Gambit

Quote
"Oliver" <oliver-no-s...@{*word*2}software.com> wrote in message

news:387D0E26.40C67302@{*word*2}software.com...
Quote
> Why does the line
> MyCheckBox->Checked = true;
> trigger the OnClick event of that checkbox?

Re:CheckBox OnClick Event


So why doesn't SpeedButton behave the same way?

To be honest it doesn't make much sense to me, that MyCheckBox->Checked = true,
invokes the eventhandler.  If I wanted to invoke the eventhandler, I'd just use
MyCheckBoxOnClick (Sender);  But I guess that's the "beauty" of C++, that
setting a property actually calls the event handler.

Is there a way to supress the OnClick event handler when setting the property
through code?  I just want to show the enduser, that a certain condition
currently exists (and let him change it by unchecking the checkbox).

--
Thanks

Oliver

If you would like to provide phone/e-mail support consulting to my company send
your qualifications to j...@{*word*2}software.com.

To reply to this post by e-mail, remove the "no-spam" from my e-mail address.

Quote
Remy Lebeau wrote:
> Because it does.

> And it even says in the documentation that it does this:

> TControl::OnClick

> Usually OnClick occurs because the user presses and releases the primary
> mouse button with the mouse pointer over the control. This event can also
> occur when

> The user selects an item in a grid, outline, list, or combo box by pressing
> an arrow key.

> The user presses Spacebar while a button or check box has focus.

> The user presses Enter when the active form has a default button (specified
> by the Default property).

> The user presses Esc when the active form has a cancel button (specified by
> the Cancel property).

> The user presses the accelerator key for a button or check box. For example,
> if the value of the Caption property of a check box is '&Bold', the B is
> underlined at runtime and the OnClick event of the check box is triggered
> when the user presses Alt+B.

> The Checked property of a radio button is set to true.

> *** The value of the Checked property of a check box is changed.

> The Click method of a menu item is called.

> Gambit

> "Oliver" <oliver-no-s...@{*word*2}software.com> wrote in message
> news:387D0E26.40C67302@{*word*2}software.com...
> > Why does the line
> > MyCheckBox->Checked = true;
> > trigger the OnClick event of that checkbox?

Re:CheckBox OnClick Event


Guess I should have searched the newsgroup first :-)  Thanks for the
pointer.

Oliver

Quote
Damon Chandler wrote:
> Hi Oliver,
> > Why does the line
> > MyCheckBox->Checked = true;
> > trigger the OnClick event of that checkbox?

> This is simply the way the control was implemented.  I agree, it doesn't
> make too much sense intuitively.

> > procedure TCustomCheckBox.SetState(Value: TCheckBoxState);
> > begin
> >  if FState <> Value then
> >  begin
> >    FState := Value;
> >    if HandleAllocated then
> >      SendMessage(Handle, BM_SETCHECK, Integer(FState), 0);
>     Click;
> >  end;
> >end;

> > In either case, shouldn't it at least be consistent?

> Yes, however, if you examine the answers to the following post, you will
> find two viable workarounds...

>       Subject: Setting Checkbox State
>          Date: Thu, 6 Jan 2000 17:16:45 -0600
>          From: "SPSmith" <ssm...@dmpnet.com>
>    Newsgroups: borland.public.cppbuilder.vcl.components.using

> Good luck!

> --
> Damon Chandler
> http://bcbcaq.freeservers.com

Re:CheckBox OnClick Event


Quote
: Oliver <oliver-no-s...@{*word*2}software.com> wrote:
>In either case, shouldn't it at least be consistent?

I agree.

--
General information:
  * Post to the right group - http://www.borland.com/newsgroups/
    * Do not cross- or multipost
      * Research at http://www.mers.com/searchsite.html

Stefan Hoffmeister - http://www.econos.de/
TeamB - http://www.teamb.com/

Re:CheckBox OnClick Event


Hi Oliver,

Quote
> Why does the line
> MyCheckBox->Checked = true;
> trigger the OnClick event of that checkbox?

This is simply the way the control was implemented.  I agree, it doesn't
make too much sense intuitively.

Quote
> procedure TCustomCheckBox.SetState(Value: TCheckBoxState);
> begin
>  if FState <> Value then
>  begin
>    FState := Value;
>    if HandleAllocated then
>      SendMessage(Handle, BM_SETCHECK, Integer(FState), 0);
    Click;
>  end;
>end;
> In either case, shouldn't it at least be consistent?

Yes, however, if you examine the answers to the following post, you will
find two viable workarounds...

      Subject: Setting Checkbox State
         Date: Thu, 6 Jan 2000 17:16:45 -0600
         From: "SPSmith" <ssm...@dmpnet.com>
   Newsgroups: borland.public.cppbuilder.vcl.components.using

Good luck!

--
Damon Chandler
http://bcbcaq.freeservers.com

Re:CheckBox OnClick Event


Quote
Oliver <oliver-no-s...@{*word*2}software.com> wrote in message

news:387D667C.2C3C27C2@{*word*2}software.com...

Quote
> So why doesn't SpeedButton behave the same way?

TSpeedButton doesn't have a Checked property, so what are you talking about
exactly?

Quote
> To be honest it doesn't make much sense to me, that MyCheckBox->Checked =
true,
> invokes the eventhandler.

It does make sense when you look at the source code for TCheckbox and see
that the OnClick event is getting triggered from the SetChecked function
(which gets called when the Checked property is changed)

Quote
> If I wanted to invoke the eventhandler, I'd just use
> MyCheckBoxOnClick (Sender);  But I guess that's the "beauty" of C++, that
> setting a property actually calls the event handler.

No, that's just how TCheckBox is written to work.  Has nothing to do with
C++ itself.

Quote
> Is there a way to supress the OnClick event handler when setting the
property
> through code?  I just want to show the enduser, that a certain condition
> currently exists (and let him change it by unchecking the checkbox).

The easiest way is to set OnClick = NULL first:

TNotifyEvent origEvent = CheckBox1->OnClick;
CheckBox1->OnClick = NULL;
CheckBox1->Checked = true;
CheckBox1->OnClick = OrigEvent;

Gambit

Re:CheckBox OnClick Event


MySpeedButton->Down = true;

in my opinion that's the same thing as
MyCheckBox->Checked = true;

Oliver

Quote
Remy Lebeau wrote:
> Oliver <oliver-no-s...@{*word*2}software.com> wrote in message
> news:387D667C.2C3C27C2@{*word*2}software.com...
> > So why doesn't SpeedButton behave the same way?

> TSpeedButton doesn't have a Checked property, so what are you talking about
> exactly?

> > To be honest it doesn't make much sense to me, that MyCheckBox->Checked =
> true,
> > invokes the eventhandler.

> It does make sense when you look at the source code for TCheckbox and see
> that the OnClick event is getting triggered from the SetChecked function
> (which gets called when the Checked property is changed)

> > If I wanted to invoke the eventhandler, I'd just use
> > MyCheckBoxOnClick (Sender);  But I guess that's the "beauty" of C++, that
> > setting a property actually calls the event handler.

> No, that's just how TCheckBox is written to work.  Has nothing to do with
> C++ itself.

> > Is there a way to supress the OnClick event handler when setting the
> property
> > through code?  I just want to show the enduser, that a certain condition
> > currently exists (and let him change it by unchecking the checkbox).

> The easiest way is to set OnClick = NULL first:

> TNotifyEvent origEvent = CheckBox1->OnClick;
> CheckBox1->OnClick = NULL;
> CheckBox1->Checked = true;
> CheckBox1->OnClick = OrigEvent;

> Gambit

Re:CheckBox OnClick Event


Only on the surface do they seem similar to you.

But if you were to delve deeper into the actual source code for setting the
Down property, you'd see it's a little more involved then setting the
Checked property of TCheckBox, and also that it DOESN'T call any event
handlers like Checked does.

Gambit

Quote
"Oliver" <oliver-no-s...@{*word*2}software.com> wrote in message

news:387E1CF1.13832C75@{*word*2}software.com...
Quote
> MySpeedButton->Down = true;

> in my opinion that's the same thing as
> MyCheckBox->Checked = true;

Re:CheckBox OnClick Event


Quote
Remy Lebeau wrote:

> *** The value of the Checked property of a check box is changed.

Most frustratingly with data access controls, every time you go to a new
record in the database....Aaargh!

 - Leo

Other Threads