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

Setting Checkbox State

87 views
Skip to first unread message

SPSmith

unread,
Jan 6, 2000, 3:00:00 AM1/6/00
to
Is there anyway to change a TCheckBox state without having it firing the
OnClick event?

Thanks,
Sean Smith

Damon Chandler

unread,
Jan 6, 2000, 3:00:00 AM1/6/00
to
Hi Sean,

> Is there anyway to change a TCheckBox state without having it firing the
> OnClick event?

When the CheckBox is actually clicked by the mouse or keyboard, it
sends it Parent the BN_CLICK notification in the form of a WM_COMMAND
message. You can derive a simple component from TCheckBox, look for
the CN_COMMAND message (WM_COMMAND's 'echo' that's sent to the CheckBox
itself), then fire a notify event (OnTrueClick) in response to the
BN_CLICK notification. From there, simply place all your OnClick code
in the OnTrueClick event handler, and you won't have to worry about it
firing when the Checked property is changed. The component will save
you time in the long run. Here's a simple example...

// in header...
class TMyCheckBox : public TCheckBox
{
private:
TNotifyEvent FOnTrueClick;
void __fastcall CNCommand(TMessage &Msg);
protected:
public:
__fastcall TMyCheckBox(TComponent* Owner);
__published:
__property TNotifyEvent OnTrueClick =
{read = FOnTrueClick, write = FOnTrueClick};

BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(CN_COMMAND, TMessage, CNCommand)
END_MESSAGE_MAP(TCheckBox)
};


// in source...
void __fastcall TMyCheckBox::CNCommand(TMessage &Msg)
{
TCheckBox::Dispatch(&Msg);
if (HIWORD(Msg.WParam) == BN_CLICKED)
{
if (FOnTrueClick) FOnTrueClick(this);
}
}


Good luck!

Damon

Stefan Hoffmeister (TeamB)

unread,
Jan 7, 2000, 3:00:00 AM1/7/00
to
: "SPSmith" <ssm...@dmpnet.com> wrote:

>Is there anyway to change a TCheckBox state without having it firing the
>OnClick event?

No, but you can unwire the event:

CurrentOnClick = CheckBox->OnClick;
CheckBox->OnClick = 0;
...
CheckBox->OnClick = CurrentOnClick;

--
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/

SPSmith

unread,
Jan 7, 2000, 3:00:00 AM1/7/00
to
Thanks for both of your suggestions. I'm not sure which one fits my
needs best yet, so I'll probably try them both.

Thanks again,
Sean Smith

0 new messages