Solved

GUI does not response when download

Posted on 2002-07-06
10
252 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
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

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
Correct Component for Shopping Cart. 2 120
Magic Software info 18 142
PHP preg_replace code convert to Delphi 14 79
how to change, disabled button color FMX ? 1 48
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

713 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