Board index » delphi » General TWinControl event ***BUG*** (or misnamed event)

General TWinControl event ***BUG*** (or misnamed event)

This is getting annoying...

I have just discovered that a number of TWinControls have event handling
problems.

Point: For some controls, 'OnClick' really does not mean 'OnClick' - it
*really* means 'OnChange'.  TRadioGroup, TCheckBox and possibly others
exhibit this.

What I am trying to do is capture user changing of a RadioGroup.
'OnClick' servicing does its thing, fine.  BUT I want to change the
state of the RadioGroup behind the scenes and I DON'T want any
additional handling done.  It took me a good chuck of this afternoon to
discover that:

1) Either 'OnClick' has a bug and will fire off its event on *any* state
change, or
2) 'OnClick' is mis-named and should be called 'OnChange'.

Does anyone have any more info on this?  Bug, or mis-named?

Please reply, BTeam...

--

Jeffrey Schrab | (work) jsch...@qdyn.com
               | (home) j_sch...@execpc.com
Quantum Dynamics International, Inc.
(920)731-0722

 

Re:General TWinControl event ***BUG*** (or misnamed event)


 If what you are trying to say is "I want to capture a change within the
Radio Group. If the change is valid, proceed.  If the change is invalid, do
not proceed within the OnClick or proceed with the OnClick."

FYI:
Within Delphi there are handles which "capture" messages.  Once the
processing of the handle is done, it will proceed to the coding within the
"OnClick".  The radio group will change it's state within the handle
procedure and not the "OnClick".  Yes it is true the "OnClick" event is
processed after the state of the RadioGroup has changed.

You need to recode the handle method and not the "OnClick" method.

 procedure WMLButtonDown(var Message: TWMLButtonDown); message
WM_LBUTTONDOWN;
 procedure WMLButtonUp(var Message: TWMLButtonUp); message WM_LBUTTONUP;

The above will "capture" the messages before the state of the RadioGroup
changes.

I don't think the "OnClick" is mis-named.  Think about it, if it were called
"OnChange" then the event will always run itself when I programically change
during run-time.  It does not do this, so that is why it is named "OnClick";
only when a mouse/<Enter> is initiated.  Keep in mind that the handles will
preprocess the control before the "OnClick" occures; that includes changes
to the state of a control...

Good Luck, :-)
David B. Smith

Jeffrey Schrab wrote in article <33F0C6AB.A1BD...@qdyn.com>...

Quote
>This is getting annoying...

>I have just discovered that a number of TWinControls have event handling
>problems.

>Point: For some controls, 'OnClick' really does not mean 'OnClick' - it
>*really* means 'OnChange'.  TRadioGroup, TCheckBox and possibly others
>exhibit this.

>What I am trying to do is capture user changing of a RadioGroup.
>'OnClick' servicing does its thing, fine.  BUT I want to change the
>state of the RadioGroup behind the scenes and I DON'T want any
>additional handling done.  It took me a good chuck of this afternoon to
>discover that:

>1) Either 'OnClick' has a bug and will fire off its event on *any* state
>change, or
>2) 'OnClick' is mis-named and should be called 'OnChange'.

>Does anyone have any more info on this?  Bug, or mis-named?

>Please reply, BTeam...

>--

>Jeffrey Schrab | (work) jsch...@qdyn.com
>               | (home) j_sch...@execpc.com
>Quantum Dynamics International, Inc.
>(920)731-0722

Re:General TWinControl event ***BUG*** (or misnamed event)


In article <33F0C6AB.A1BD...@qdyn.com>, jsch...@qdyn.com says...

Quote
> What I am trying to do is capture user changing of a RadioGroup.
> 'OnClick' servicing does its thing, fine.  BUT I want to change the
> state of the RadioGroup behind the scenes and I DON'T want any
> additional handling done.  It took me a good chuck of this afternoon to
> discover that:

> 1) Either 'OnClick' has a bug and will fire off its event on *any* state
> change, or
> 2) 'OnClick' is mis-named and should be called 'OnChange'.

> Does anyone have any more info on this?  Bug, or mis-named?

Not a bug, not mis-named a fairly well documented feature ;)
From Delphi2 help file:

Declaration

property OnClick: TNotifyEvent;

Description

The OnClick event occurs when the user clicks the component. Typically,
this is when the user presses and releases the primary mouse button with
the mouse pointer over the component. This event can also occur when

*       The user selects an item in a grid, outline, list, or combo box by
        pressing an arrow key.

*       The user presses Spacebar while a button or check box has focus.

*       The user presses Enter when the active form has a default button
        (specified by the Default property).

*       The user presses Esc when the active form has a cancel button
        (specified by the Cancel property).

*       The user presses the accelerator key for a button or check box.
        For example, if the value of the Caption property of a check box
        is '&Bold', the B is underlined at run time and the OnClick event
        of the check box is triggered when the user presses Alt+B.

*       The Checked property of a radio button is set to True.

*       The value of the Checked property of a check box is changed.
*
        The Click method of a menu item is called.

For a form, an OnClick event occurs when the user clicks a blank area of
the form or on a disabled component.
_____________
End Quote

As you see there are several different thing in different situation that
can trigger this powerful event.

Good hunting,
--
                  Yours sincerly
____________________________________________________
                Daniel W. Mathiasen
                 LPTdata, Denmark
                 [+45] 7642 8487
              For reply: Remove NoSpam

Re:General TWinControl event ***BUG*** (or misnamed event)


Daniel W. Mathiasen <d...@lpt.dk> wrote in article
<MPG.e5c0db9a7f26fb7989690@wingate>...

Quote
> In article <33F0C6AB.A1BD...@qdyn.com>, jsch...@qdyn.com says...
> > What I am trying to do is capture user changing of a RadioGroup.
> > 'OnClick' servicing does its thing, fine.  BUT I want to change the
> > state of the RadioGroup behind the scenes and I DON'T want any
> > additional handling done.

It's not a bug. It's just the way it works. To do what you want to do you
need a 'state' variable
 e.g. ChangingByCode: Boolean; {initially FALSE}

In your OnClick procedure do

IF NOT ChangingByCode THEN
   BEGIN
   ...<etc etc>
   END

When you want to change the radio button without triggering the code you
do:

ChangingByCode:=TRUE;
TRY
  ...<Change radio buttons>
  ...<etc etc>
FINALLY
  ChangingByCode:=FALSE;
END;

Problem solved?

Other Threads