Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Change CheckBox state w/o triggering OnClick event

Posted on 1999-08-10
10
Medium Priority
?
420 Views
Last Modified: 2010-05-18
In C++Builder 3, how do I change the CheckBox state w/o triggering the OnClick() event?
0
Comment
Question by:boseefus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 2

Author Comment

by:boseefus
ID: 1393950
Adjusted points to 50
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1393951
hi boseefus,

i'm not familiar with C++,
but change simple the checked property

meikl
0
 
LVL 2

Author Comment

by:boseefus
ID: 1393952
Nope. It fires the OnClick() event handler. So does changing the State to cbChecked.

Delphi and C++Builder should behave EXACTLY the same in this respect, as the VCL is Object Pascal.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:m_adil
ID: 1393953
Hi, boseefus
Try this

CheckBox1->Checked = false;
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1393954
Well, you could temporarily delete the OnClick handler:

var OnClickProc : procedure (sender: TObject) of object;
begin
  OnClickProc:=checkbox1.OnClick;
  checkbox1.OnClick:=nil;
  checkbox1.Checked:=false;
  checkbox1.OnClick:=OnClickProc;
end;

Ugly, but should work...

Regards, Madshi.
0
 
LVL 4

Expert Comment

by:Radler
ID: 1393955
Hi;


There are the possibilite that, changing the property State=cbChecked( if this exists at CBuilder) the event don't be called ?

T++, Radler.
0
 
LVL 2

Author Comment

by:boseefus
ID: 1393956
m_adil: No. The whole point of my question is that changing the Checked property DOES trigger the OnClick() event. See my subsequent comment of
Tuesday, August 10 1999 - 09:17AM PDT.

Madshi: That's damned sneaky! It's also indeed ugly, but it does work and is clever. Lock it! I wonder what Borland's recommended method would be.

Radler: Please read my subsequent response to comment kretzschmar of
Tuesday, August 10 1999 - 09:17AM PDT
0
 
LVL 20

Accepted Solution

by:
Madshi earned 200 total points
ID: 1393957
Sorry for the ugly answer...   :-)

Well, it's the only possible answer I see, so I guess that it must be Borland's recommended method, too.

Regards, Madshi.
0
 
LVL 2

Author Comment

by:boseefus
ID: 1393958
So, the cleaned up code would look something like this:

//---------------------------------------------------------------------------
void      __fastcall      TForm1::SetCheckBox (TCheckBox *aChkBox, bool aChkState)
{
      TNotifyEvent      SavedOnClickEventHandler = aChkBox->OnClick;
      aChkBox->OnClick = NULL;
      aChkBox->Checked = aChkState;
      aChkBox->OnClick = SavedOnClickEventHandler;
}

0
 
LVL 2

Author Comment

by:boseefus
ID: 1393959
So, the cleaned up code would look something like this:

//---------------------------------------------------------------------------
void      __fastcall      TForm1::SetCheckBox (TCheckBox *aChkBox, bool aChkState)
{
      TNotifyEvent      SavedOnClickEventHandler = aChkBox->OnClick;
      aChkBox->OnClick = NULL;
      aChkBox->Checked = aChkState;
      aChkBox->OnClick = SavedOnClickEventHandler;
}

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question