Solved

Show Modal form without stopping the program

Posted on 1998-09-11
4
1,174 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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