Solved

GUI does not response when download

Posted on 2002-07-06
10
254 Views
Last Modified: 2010-04-04
I have one application which is to download file from web.
But when it runs, the GUI sometime look like freeze and no response to my mouse click.
Even if I add some code such as application.processmessage
it is still same as above.

Can any one help me?
0
Comment
Question by:wangzheng
[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
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 7

Expert Comment

by:Cynna
ID: 7133826
wangzheng,

You'll have to provide more info...

Where did you put Application.Processmessage?
Is the download processed from the main thread?

Please post code example (how do you call your download
function, how does the download function looks like....)

0
 
LVL 1

Expert Comment

by:chengjian
ID: 7135042
hi Wang

I think you may use a thread to download, or if you use indy, it provide an anti-fraz stuff.

Best Regards
0
 
LVL 1

Assisted Solution

by:herr_apfelschnitt
herr_apfelschnitt earned 50 total points
ID: 7136078
You have to put the downloading code in a seperate thread. If you put it in the main VCL thread, messages can't be processed until the download is finished (if the download happens synchroneously, and that's what it looks like. if not, then this is totally useless :D ). Could you tell us HOW your program downloads the file(s)?

For more information on threads in Delphi:
http://www.pergolesi.demon.co.uk/prog/threads/ToC.html

Just do "New..." (at least in Delphi 3) and make a new thread object. Put the downloading code in the Execute procedure.

Btw: To cynna, I tried Application.ProcessMessages a few times, and it allows you to click buttons, but those clicks weren't actually processed (no OnClick etc. procedures executed). What does ProcessMessages actually do?

Hope this helps,
herr_apfelschnitt
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:chengjian
ID: 7136737
to herr_apfelschnitt :

if the code like this:

while ... do begin
 func1;
 proc2;
 func3;
 for...do
  ...;
 application.processmessages;
end;

the application.processmessages alow you click the button, but the OnClick event would not execute imediatly, but it would execute until the next time (or next few times) application.processmessages excuted.
0
 
LVL 7

Expert Comment

by:Cynna
ID: 7137040
herr_apfelschnitt,

> ... and it allows you to click buttons, but those clicks weren't actually processed....

Your loop code didn't got around to the ProcessMessages line.
Take a look at chengjian post.


> What does ProcessMessages actually do?

Well, exactly what its name suggests :) - it makes the main VCL thread stop for a moment, take whatever message it has in a message queue, and fire a proper event for it.
Event handler code is then executed, and after it's finished, the lines after ProcessMessages are continued to be executed.
0
 
LVL 1

Expert Comment

by:herr_apfelschnitt
ID: 7137204
I think I did put it within the loop. But I guess I probably screwed up somewhere (as I tend to do quite often :D )
0
 

Author Comment

by:wangzheng
ID: 7142423
How can I move my codes into a thread?
Because I know little about thread.
In the maim thread, I have used some VCL components, can I also use them in a thread?


0
 
LVL 7

Accepted Solution

by:
Cynna earned 50 total points
ID: 7142867
wangzheng ,

> How can I move my codes into a thread?
> Because I know little about thread.

Threads can make your head hurt if you don't understand them and trying to implement them ;). I really suggest you take some time to learn about multithreading, and then get back to your project.
These are some online resources that should help enough to get you started:

* Multithreading - The Delphi Way :  <--- A MUST!
 http://www.pergolesi.demon.co.uk/prog/threads/ToC.html

* Delphi threading by example:
 http://community.borland.com/article/0,1410,22411,00.html

* Better Threads For The VCL
http://www.midnightbeach.com/jon/pubs/MsgWaits/MsgWaits.html


>In the maim thread, I have used some VCL components, can I also use them in a thread?

Principally yes, but this is not a good practice. It *will* get you in trouble sooner or later.
You should always try to design your code so that the VCL operations stays separated in a main thread, and "real" processing is performed in your threads.
0
 

Expert Comment

by:CleanupPing
ID: 9343098
wangzheng:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 9460242
wangzheng,
No comment has been added lately (18 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: split points between herr_apfelschnitt http:#7136078 and Cynna http:#7142867

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --

Thanks,

anAKiN
EE Cleanup Volunteer
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
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…

689 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