Normally when you open a dialog using ShowModal, execution of the current thread halts until the dialog is closed. I want to display a Modal dialog, but continue execution on the current thread while the dialog is still open.
By "Modal" I simply mean that the user can not interact with any of the other forms of the application till the modal dialog is closed.
The Delphi ShowModal function provides a slightly different definition of "Modal" to the one I require:
A modal form is one where the application can't continue to run until the form is closed.
Currently I have code like this:
dialog.Parent:=self;
dialog.Show;
// keep doing stuff...
This works, except I can still interact with the parent window (move it around, close it etc)
How do I show a form that stops the user from interacting with the parent window, without using ShowModal?
Open the source code of Delphi\Source\VCL\Forms.pas and open implementation of ShowModal. Then learn how it works. I can't copy the source code here as it's an IP of CodeGear, but you can do this yourself easily and reuse parts of it's code.
Even with a modal form open, the main thread still executes (otherwise the modal form could not repaint itself).
Modal forms however have their own event loop, preventing the original application event loop from executing.
They have to (just like Windows message boxes have to as well), as otherwise you could have an event sneak back into the main event loop creating yet another modal form or messagebox.
And that kind of negates the whole point of being modal: there can be only one modal form or messagebox per UI thread.
So you need to ask yourself this question:
What actions in the main event loop does this modal form prevent from happening?
Then move those actions into a separate thread.
--jeroen
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With