Solved

GUI does not response when download

Posted on 2002-07-06
10
246 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
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 7

Expert Comment

by:Cynna
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 1

Expert Comment

by:chengjian
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 1

Expert Comment

by:herr_apfelschnitt
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now