?
Solved

GUI does not response when download

Posted on 2002-07-06
10
Medium Priority
?
256 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 200 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 200 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

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!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

764 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