Events within Events

This is a discussion on Events within Events within the Delphi forums in Programming Languages category; Hi, Trying to track down some subtle bugs in my app that may be related to reentry, Is it possible for a on timer event to trigger before a on shortcut event is finished or even the opposite... a on shortcut event before a on timer event is finished. A pointer to a document on these issues would be helpfull. many thanks, -rvg...

Go Back   Application Development Forum > Programming Languages > Delphi

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-05-2008, 06:32 AM
Robert Van Gemert
Guest
 
Default Events within Events

Hi,

Trying to track down some subtle bugs in my app that may be related to
reentry, Is it possible for a on timer event to trigger before a on shortcut
event is finished or even the opposite... a on shortcut event before a on
timer event is finished.

A pointer to a document on these issues would be helpfull.

many thanks,
-rvg


Reply With Quote
  #2  
Old 08-05-2008, 07:09 AM
Peter Below (TeamB)
Guest
 
Default Re: Events within Events

Robert Van Gemert wrote:

> Hi,
>
> Trying to track down some subtle bugs in my app that may be related
> to reentry, Is it possible for a on timer event to trigger before a
> on shortcut event is finished or even the opposite... a on shortcut
> event before a on timer event is finished.
>
> A pointer to a document on these issues would be helpfull.


If you make the error of calling Application.ProcessMessages inside an
event handler (any event handler) it can lead to another event being
fired before the one you are in returns to the message loop.



--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com
Reply With Quote
  #3  
Old 08-05-2008, 07:53 AM
John Herbster
Guest
 
Default Re: Events within Events


"Robert Van Gemert" wrote
> Trying to track down some subtle bugs in my app
> that may be related to reentry, ...


Have you checked for reentry?
You know that you could add a boolean var InMyEvent and
on entry to the event check that it is false and set it
to true. Put the rest of the event code in a
try-finally-end block where in the finally block you set
InMyEvent back to false. If InMyEvent is not false at
the entry you can check the calling stack.
HTH, JohnH
Reply With Quote
  #4  
Old 08-06-2008, 03:27 AM
Robert Van Gemert
Guest
 
Default Re: Events within Events

Peter & John,

I was calling App.ProcessMessages!, intentionally but not fully realizing
how it can break the windows message system.

Thanks.
-rvg


Reply With Quote
  #5  
Old 08-06-2008, 10:18 PM
Iain Macmillan
Guest
 
Default Re: Events within Events

In article <4899525c$1@newsgroups.borland.com>, "Robert Van Gemert"
<rcvangemert@optushome.com.au> wrote:


> Peter & John,
>
> I was calling App.ProcessMessages!, intentionally

I've seen some here suggest that if you ever find you need to make this
call, you know you are doing something wrong somewhere else.

> but not fully realizing
> how it can break the windows message system.

Not sure if that is why they say it, perhaps it can break other things too!
Reply With Quote
  #6  
Old 08-07-2008, 02:30 AM
Anders Isaksson
Guest
 
Default Re: Events within Events

Robert Van Gemert wrote:

> I was calling App.ProcessMessages!, intentionally but not fully realizing
> how it can break the windows message system.


It is not actually 'breaking' anything, it's doing exactly what you're
telling it: That it's ok to activate another event handler before you have
finished with the current one. If you don't realize what effect this will
have on your program, don't use Application.ProcessMessages.

If you for example have A.P in a long loop in an event (ButtonClick, for
example), to keep the user interface 'responsive', then *every* button, menu
item, mouse-over, etc. is allowed to be called *while you're still looping in
the original event*.

Google for "A.P considered harmful" or something like that, and I believe you
can find code for a 'safe' message handler to call, if all you want to do is
keeping the window visually updated during a longer calculation.

Read up on threads if you want to do work in the background, while the UI is
still fully responsive.

--
Anders Isaksson, Sweden
BlockCAD: http://web.telia.com/~u16122508/proglego.htm
Gallery: http://web.telia.com/~u16122508/gallery/index.htm
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 05:27 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.