Board index » delphi » INPRISE READ!!! D4 Update #2 Errors!!!!

INPRISE READ!!! D4 Update #2 Errors!!!!

TCheckbox.OnClick sends applications into recursive loop.  Place TCheckbox
on new form.  In the OnClick place:
"CheckBox1.Checked:=not CheckBox1.Checked;"

Now run, check the box! I dare you to check the box and watch it re-check
and uncheck itself til the stack overflows!!!

 

Re:INPRISE READ!!! D4 Update #2 Errors!!!!


Quote
In article <713o4o$8...@forums.borland.com>, Mike B. wrote:
> TCheckbox.OnClick sends applications into recursive loop.  Place TCheckbox
> on new form.  In the OnClick place:
> "CheckBox1.Checked:=not CheckBox1.Checked;"

> Now run, check the box! I dare you to check the box and watch it re-check
> and uncheck itself til the stack overflows!!!

This is not a bug. If you look at the help you will see that the OnClick
event is generated whenever the value of the checkbox changes, whether
because the user has clicked on it, toggled it with a hot key or (as in your
code) changed it programmatically.

If there is a bug it is that the event should be called OnChange: in my
early Delphi days I wasted a lot of time trying to find out how to detect
that a checkbox or rg had changed, thinking that OnClick was generated by a
mouse click and nothing else.

Tony Bryer   SDA UK

Re:INPRISE READ!!! D4 Update #2 Errors!!!!


Mike:

That's your bug, not Inprise's. Causing a click in an OnClick handler will
cause recursion. If you want to avoid it use:

CheckBox1.OnClick := nil
try
  CheckBox1.Checked:=not CheckBox1.Checked;
finally
  CheckBox1.OnClick := CheckBox1OnClick;
end;

--
Regards
Ralph (TeamB)
Herrsching, Germany
(TeamB cannot respond to questions received via email)

Quote
Mike B. wrote in message <713o4o$8...@forums.borland.com>...

|TCheckbox.OnClick sends applications into recursive loop.  Place TCheckbox
|on new form.  In the OnClick place:
|"CheckBox1.Checked:=not CheckBox1.Checked;"
|
|Now run, check the box! I dare you to check the box and watch it re-check
|and uncheck itself til the stack overflows!!!

Re:INPRISE READ!!! D4 Update #2 Errors!!!!


Quote
On Tue, 27 Oct 1998 00:10:42 -0600, Mike B. wrote:
> TCheckbox.OnClick sends applications into recursive loop.  Place TCheckbox
> on new form.  In the OnClick place:
> "CheckBox1.Checked:=not CheckBox1.Checked;"

> Now run, check the box! I dare you to check the box and watch it re-check
> and uncheck itself til the stack overflows!!!

It's not a bug. It works this way also in Delphi 3!

Also, what you're trying to do, is not making any sense. TCheckbox itself
toggle the State property when the control is clicked, so it's no need to
do it yourself too.

If you want to preserve the Checked property, I.e. not allow the user to
change it, use Enabled := false, etc.

--
Miha Remec

Re:INPRISE READ!!! D4 Update #2 Errors!!!!


That's not Delphi error!!  it is simply wrong coding method...

Everyone know that you cannot do that, until you manage to exit this loop
with some variable...

Quote
Mike B. wrote in message <713o4o$8...@forums.borland.com>...
>TCheckbox.OnClick sends applications into recursive loop.  Place TCheckbox
>on new form.  In the OnClick place:
>"CheckBox1.Checked:=not CheckBox1.Checked;"

>Now run, check the box! I dare you to check the box and watch it re-check
>and uncheck itself til the stack overflows!!!

Re:INPRISE READ!!! D4 Update #2 Errors!!!!


another way, if you don't want exceptions stopping your debug session:

Box.OnClick := nil;
Box.Checked := not Box.Checked;
Box.OnClick := OnClick;

Quote
Ralph Friedman (TeamB) wrote:
> Mike:

> That's your bug, not Inprise's. Causing a click in an OnClick handler will
> cause recursion. If you want to avoid it use:

> CheckBox1.OnClick := nil
> try
>   CheckBox1.Checked:=not CheckBox1.Checked;
> finally
>   CheckBox1.OnClick := CheckBox1OnClick;
> end;

> --
> Regards
> Ralph (TeamB)
> Herrsching, Germany
> (TeamB cannot respond to questions received via email)

> Mike B. wrote in message <713o4o$8...@forums.borland.com>...
> |TCheckbox.OnClick sends applications into recursive loop.  Place TCheckbox
> |on new form.  In the OnClick place:
> |"CheckBox1.Checked:=not CheckBox1.Checked;"
> |
> |Now run, check the box! I dare you to check the box and watch it re-check
> |and uncheck itself til the stack overflows!!!

Re:INPRISE READ!!! D4 Update #2 Errors!!!!


whoops.. I misread Ralph's code.. I thought it was a try except block with the
event handler enabled.. his code doesn't cause an exception, and is a safer
version of what I wrote.. sorry Ralph.
Quote
Enrique Flores wrote:
> another way, if you don't want exceptions stopping your debug session:

> Box.OnClick := nil;
> Box.Checked := not Box.Checked;
> Box.OnClick := OnClick;

> Ralph Friedman (TeamB) wrote:

> > Mike:

> > That's your bug, not Inprise's. Causing a click in an OnClick handler will
> > cause recursion. If you want to avoid it use:

> > CheckBox1.OnClick := nil
> > try
> >   CheckBox1.Checked:=not CheckBox1.Checked;
> > finally
> >   CheckBox1.OnClick := CheckBox1OnClick;
> > end;

> > --
> > Regards
> > Ralph (TeamB)
> > Herrsching, Germany
> > (TeamB cannot respond to questions received via email)

> > Mike B. wrote in message <713o4o$8...@forums.borland.com>...
> > |TCheckbox.OnClick sends applications into recursive loop.  Place TCheckbox
> > |on new form.  In the OnClick place:
> > |"CheckBox1.Checked:=not CheckBox1.Checked;"
> > |
> > |Now run, check the box! I dare you to check the box and watch it re-check
> > |and uncheck itself til the stack overflows!!!

Other Threads