One of the things you must be careful with is reentrancy in your application through a message loop.
The most obvious way is Application.ProcessMessages: it will loop until all messages from the Windows message queue are processed, whether your application is ready for them or not.
A less obvious way is because of modal dialogs or forms. They have their own message loop which might cause global reentrancy in your application (for instance through TTimer objects).
That was the case for this problem: stack overflow with repeated DispatchMessageW in the call stack.
A couple of ways to try to avoid these issues:
- Don’t cause a secondary message loop.
You can refrain from calling Application.ProcessMessages, but you cannot always avoid modal dialogs. - Protect each of your event handlers by disabling the path to it as soon as it gets called.
This means disabling the Enabled property for instances of TTimer, TControl, TAction, or other objects that cause events.
–jeroen
via: windows – stack overflow with repeated DispatchMessageW in the call stack – Stack Overflow.
Filed under: Delphi, Development, Software Development