Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

D4: How to set CheckBox.Checked without firing OnClick ?

0 views
Skip to first unread message

Dets

unread,
Feb 24, 1999, 3:00:00 AM2/24/99
to
Hi there.

I have a problem with the TCheckbox. Whenever I set it's
Checked-Property to TRUE by code, it fires it's OnClick-event.

I need to display the single bits of a word-value of a database-field.
When opening the query, I need to set the Checked-property of the
checkboxes to display the values of the bits, but when setting them,
they fire OnClick, causing a call to my routine to calculate the new
word value again. How can I prevent that ?

TIA, Dets ...


Dets

unread,
Feb 24, 1999, 3:00:00 AM2/24/99
to
Thanks, Rick. I'm sure that'll work !
Dets...

Rick Rogers (TeamB) schrieb:

> On Wed, 24 Feb 1999 16:15:26 +0100, Dets <de...@caix.net> wrote:
>
> > Whenever I set it's Checked-Property to TRUE by code,
> > it fires it's OnClick-event.
>

> True, that is by design and as documented.


>
> > How can I prevent that ?
>

> Set the event property to nil, like this:
>
> var
> Saved: TNotifyEvent;
> begin
> Saved := CheckBox1.OnClick;
> CheckBox1.OnClick := nil;
> CheckBox1.Checked := { some value };
> CheckBox1.OnClick := Saved;
> end;
>
> Or use a semaphore boolean variable like this:
>
> procedure TForm1.CheckBox1Click(Sender: TObject);
> begin
> if Updating then Exit;
> { Do something useful here }
> end;
>
> begin
> Updating := True;
> CheckBox1.Checked := { some value };
> Updating := False;
> end;
>
> --
> Rick Rogers (TeamB) | Fenestra Technologies
> http://www.fenestra.com/


Rick Rogers (TeamB)

unread,
Feb 24, 1999, 3:00:00 AM2/24/99
to

Wayne Niddery (TeamB)

unread,
Feb 24, 1999, 3:00:00 AM2/24/99
to
Dets wrote in message <36D4178E...@caix.net>...

>
>I need to display the single bits of a word-value of a database-field.
>When opening the query, I need to set the Checked-property of the
>checkboxes to display the values of the bits, but when setting them,
>they fire OnClick, causing a call to my routine to calculate the new
>word value again. How can I prevent that ?


As Rick has indicated, this is the normal behaviour for the check box.

Question: Do you need to recalc the word value each time a checkbox is
changed, or only when the user posts the record back? If the latter, then
take the code out of the OnClick events and move it to the BeforePost event
of the TTable or TQuery.

--
Wayne Niddery - WinWright Consulting
Delphi, C++Builder, JBuilder, InterDev --
http://home.ican.net/~wniddery/RADBooks.html
...remove chaff when replying...
"You know you've landed gear-up when it takes full power to taxi"

Richey / Delphi-Box

unread,
Feb 25, 1999, 3:00:00 AM2/25/99
to
just curious : is this normal behaviour by design ?

This also costed me hours to fix, and it doesn't really seem
logical to me. Maybe this could be *fixed* in an upcoming
update pack.

Richey


On Wed, 24 Feb 1999 15:25:25 GMT, ri...@fenestra.com (Rick Rogers
(TeamB)) wrote:

>On Wed, 24 Feb 1999 16:15:26 +0100, Dets <de...@caix.net> wrote:
>
>> Whenever I set it's Checked-Property to TRUE by code,
>> it fires it's OnClick-event.
>
>True, that is by design and as documented.
>

>> How can I prevent that ?
>

>Set the event property to nil, like this:
>
>var
> Saved: TNotifyEvent;
>begin
> Saved := CheckBox1.OnClick;
> CheckBox1.OnClick := nil;
> CheckBox1.Checked := { some value };
> CheckBox1.OnClick := Saved;
>end;
>
>Or use a semaphore boolean variable like this:
>
>procedure TForm1.CheckBox1Click(Sender: TObject);
>begin
> if Updating then Exit;
> { Do something useful here }
>end;
>
>begin
> Updating := True;
> CheckBox1.Checked := { some value };
> Updating := False;
>end;

_______________________________________________________________
http://Inner-Smile.com, home of:
INF-Tool - create *smaller* setup packages for your programs!
Resource-Grabber - giving you 1000's of glyphs,images,icons,sounds..
Richey's Delphi-Box - 1000+ links and answers for Delphi developers
..one of the best starting points for Delphi developers worldwide..

Peter Below (TeamB)

unread,
Feb 25, 1999, 3:00:00 AM2/25/99
to
In article <36d877a5...@forums.inprise.com>, Richey / Delphi-Box
wrote:

> just curious : is this normal behaviour by design ?
>
It is how the Windows combo box control has been implemented by
Microsoft: the control sends a BN_CLICKED notification to its parent
when the state changes, whether by user action or program. There is no
way to distinguish between these two sources of the notification, which
fires the OnClick event.

> Maybe this could be *fixed* in an upcoming
> update pack.
>

It is not broken in the first place.

Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitely requested!


David Gottschalk

unread,
Mar 15, 1999, 3:00:00 AM3/15/99
to
On Wed, 24 Feb 1999 16:15:26 +0100, Dets <de...@caix.net> wrote:

>Hi there.
>
>I have a problem with the TCheckbox. Whenever I set it's


>Checked-Property to TRUE by code, it fires it's OnClick-event.
>

>I need to display the single bits of a word-value of a database-field.
>When opening the query, I need to set the Checked-property of the
>checkboxes to display the values of the bits, but when setting them,
>they fire OnClick, causing a call to my routine to calculate the new

>word value again. How can I prevent that ?
>
>TIA, Dets ...
>

Try this

procedure CheckNoClick( const aCB: TCheckBox; const aCheckIt:
Boolean);
begin
aCB.Perform(BM_SETCHECK, Ord(aCheckIt), 0);
end;

Regards,
David Gottschalk

0 new messages