• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 260
  • Last Modified:

GUI does not response when download

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
wangzheng
Asked:
wangzheng
  • 3
  • 2
  • 2
  • +3
2 Solutions
 
CynnaCommented:
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
 
chengjianCommented:
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
 
herr_apfelschnittCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
chengjianCommented:
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
 
CynnaCommented:
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
 
herr_apfelschnittCommented:
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
 
wangzhengAuthor Commented:
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
 
CynnaCommented:
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
 
CleanupPingCommented:
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
 
Lukasz LachCommented:
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

Technology Partners: 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!

  • 3
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now