[DUG] Debugging on TS

Max Nilson max at accredo.co.nz
Fri Jul 29 21:36:25 NZST 2005


Stephen Barker suggested: 

> Maybe you could change the btnclick to not close the form but 
> post a wm_close message to it?

After Rohit complained:

> > One of the major flaws in windoze... where the btnclick 
> > closes a form  the btnup event can go to some other form.

Another variation on this theme is that you have two related events on the
queue, call them event1 and event2, and event2 relies on event1 having been
fully handled. If you event get a situation where the processing for event1
is reentrant into ProcessMessages you can get event2 being processed before
event1 has completed. Instant nasty stuff happens.

After having this problem in so many different guises in our application I
finally gave up and created a delayed event handler. You send place a class
on the delayed event list and eventually when the application is idle and at
the highest level process message loop it take the event class of the list
and processes it. I uses classes on the list so that I can create various
different specialisations that can contain enough context to know what to
do. This works around the problem of only having 64bits of user data in a
PostMessage/SendMessage call (that is the total of wParam and lParam). And
it provides for type safe parameters into the delayed events, rather than
having to do weird casting on the wParam and lParam.

This totally solved the issue of Windows event dispatching destroying forms
and components, but it does leave open the window for an event related to an
destroyed object to be sitting on the list waiting for its turn. So the
delay event mechanism also handles various notifications for the different
classes of objects in the list, so that events for any object being
destroyed are removed before execution.

After getting that sort I now have a bullet proof delayed event mechanism,
and all of our buttons, speed buttons, other clickable objects pass their
actions through the delayed event handler. This has removed all of the AV's,
exceptions and other timing wierdness from the application by making the
events serialised and predictable, and debuggable. Something that can't be
seid for the Windows event queue.

Cheers, Max.





More information about the Delphi mailing list