Change CheckBox state w/o triggering OnClick event

In C++Builder 3, how do I change the CheckBox state w/o triggering the OnClick() event?
LVL 2
boseefusAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

boseefusAuthor Commented:
Adjusted points to 50
0
kretzschmarCommented:
hi boseefus,

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

meikl
0
boseefusAuthor Commented:
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
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

m_adilCommented:
Hi, boseefus
Try this

CheckBox1->Checked = false;
0
MadshiCommented:
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
RadlerCommented:
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
boseefusAuthor Commented:
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
MadshiCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
boseefusAuthor Commented:
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
boseefusAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.