Board index » delphi » Event-handlers without recursive calls.

Event-handlers without recursive calls.

In our project we have events we are afraid might
cause a recursive build-up on the stack.  

So we are thinking of doing it through messages or the
Idle-handle.

Though this must be a common problem in event-driven
programming? --- so do anyone have library- or sample-
code for this (I guess you cant do it generically
with parameters, but ... )  or a pointer to an article
about this form of event-driven-programming?

Thanks!
 _
| | |  _     _        http://www.stud.ntnu.no/~olavb/
|_| |_|_|_|_|                     mailto:Ol...@dds.nl
Eyecom Images, Amsterdam

 

Re:Event-handlers without recursive calls.


The easiest way to avoid recursion is with a form level flag.

When an event is called, check this flag.  If it is set then exit the event
procedure.

If it wasn't set, set it and proceed as normal.  Once you have finished
clear it again.

procedure Edit1.Change;
begin
        if blInternalChg then
                Exit;

        blInternalChg := True;
        Edit2.Text := 'SomeText';
        blInternalChg := False;
end;

procedure Edit2.Change;
begin
        if blInternalChg then
                Exit;

        blInternalChg := True;
        Edit1.Text := 'SomeMoreText';
        blInternalChg := False;
end;

--
Mark Pritchard
-------------
http://www.ozemail.com.au/~pritchma

Olav <Ol...@dds.nl> wrote in article <32524D56.5...@dds.nl>...

Quote
> In our project we have events we are afraid might
> cause a recursive build-up on the stack.  

> So we are thinking of doing it through messages or the
> Idle-handle.

> Though this must be a common problem in event-driven
> programming? --- so do anyone have library- or sample-
> code for this (I guess you cant do it generically
> with parameters, but ... )  or a pointer to an article
> about this form of event-driven-programming?

Re:Event-handlers without recursive calls.


Quote
Olav wrote:

> In our project we have events we are afraid might
> cause a recursive build-up on the stack.

> So we are thinking of doing it through messages or the
> Idle-handle.

> Though this must be a common problem in event-driven
> programming? --- so do anyone have library- or sample-

 about this form of event-driven-programming?

I have been doing event-driven programming for 5 years, and very seldom
have run into this problem.  Usually it is fairly easy to change your
code to fix it.  Can you give more details on your situation?

Roger Hernandez
rog...@shadow.net

Other Threads