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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
MadshiConnect With a Mentor Commented:
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
 
boseefusAuthor Commented:
Adjusted points to 50
0
 
kretzschmarCommented:
hi boseefus,

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

meikl
0
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
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
 
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
 
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
All Courses

From novice to tech pro — start learning today.