Solved

Show Modal form without stopping the program

Posted on 1998-09-11
4
1,193 Views
Last Modified: 2012-05-04
I have an application in which there are several forms. One of them is a mail client to receive pop3 mail messages. My problem occurs when the messages are downloading, I like to let the user go to other forms. Some of these forms have modal dialogs. When one of these dialogs is opened, the download stops. What can I do to prevent that, threads maybe ? any example ?

Thank you.
0
Comment
Question by:sharons
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 20

Accepted Solution

by:
Madshi earned 30 total points
ID: 1339478
sharons,

it's quite complicated. I'll try to explain...
There is an important difference between form.Show and form.ShowModal. The first method shows the form and returns at once. The second method shows the form and does NOT return, but stays in a little loop like:
  while not Application.Terminated do
    Application.HandleMessage;
That means, all messages are processed, but Delphi stays in the ShowModal method.
I guess your download form has a little loop like the above one, too (perhaps Application.ProcessMessages instead of Application.HandleMessage). So probably this is happening:
Your download form downloads some bytes. Then it calls ProcessMessages. In ProcessMessages there comes a message that the user wants to open a modal form. So ProcessMessages calls ShowModal. But ShowModal doesn't return. So the ProcessMessages call in the download form's loop doesn't return either...

I hope you understand the problem right now. So what can you do to avoid such a situation? You suggested threads. But that won't help because you can't call something like ShowModal in a delphi thread, because Delphi's VCL isn't reentrant :-(. You could call ShowModal in the synchronize function of a delphi thread. But then the same sh... will happen like it happens now.

So my suggestion for you:
Change your download programming style. Delete the ProcessMessages loop. Instead of staying in that download function you should call it again and again, until the download is finished. There are three ways to do it like this:
(1) In the end of your download function you can post a message to yourself (e.g. WM_USER+77). Then you have to define a message handler for that message that just calls your download function again. So you can avoid that "message deadlock".
(2) Call your download function with a little timer.
(3) Use the Application.OnIdle event to call your download function.

Hope this helps...
Regards, Madshi.
0
 

Author Comment

by:sharons
ID: 1339479
Thank you Madshi.

What do you think about the following:

I have my main application. I call the method that downloads the email messages from within a separate thread. While the separate thread downloads the messages, the main application calls show modal.  Would the download be stoped then ?  Thank you.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1339480
sharons,

ok, variant number (4).   :-)

But be cautious with what you do in this thread, because (as I said before) the VCL is not reentrant (is it written this way?).
So changes in your download form (e.g. a progress bar) should be made with the thread.synchronize method.

Regards, Madshi.

P.S: Did you really understand my loooooooong garbage?
0
 

Author Comment

by:sharons
ID: 1339481
Thank you for your time. I have decided to limit the navigation while download occur.  I think it will be safer like that. The download functions are parts of components which I did not write myself. I prefer not to change them as a new release is coming up soon.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question