Delphi 7 uses Idhttp crawl Web page to solve the phenomenon of suspended animation

Source: Internet
Author: User

Use Idhttp to crawl Web pages in Delphi 7, causing the window to be unresponsive to the state of suspended animation. Two methods are available through search.

1. Write in the thread, but the call is more troublesome

2. Use the Idantifreeze provided by Delphi (Indy must be installed). Put Idfreeantifreeze into the program in Indy misc,

Modify the Onlywhenidle state to false. Convenient and simple.

=====================================

Take the Delphi control Indy component directly as an example. Create a new project, put a Tidhttpcontrol control, a Tidantifreezecontrol control, A tprogressbar is used to display the download progress. Finally put the last TButton to start executing our command. The code is as follows:

Procedure Tform1.button1click (Sender:tobject);//Click on the button to start downloading our files
Var
Mystream:tmemorystream;
Begin
The idantifreeze1.onlywhenidle:=false;//settings make a response.
Mystream:=tmemorystream.create;
Try
Idhttp1.get (' Http://www.138soft.com/download/Mp3ToExe.zip ', mystream);//Download My Site a zip file
Except//indycontrol control to use this try: Except structure.
ShowMessage (' Network error! ');
Mystream.free;
Exit;
End
Mystream.savetofile (' C:\Mp3ToExe.zip ');
Mystream.free;
ShowMessage (' OK ');
End

Procedure Tform1.idhttp1workbegin (Sender:tobject; Aworkmode:tworkmode;
const aworkcountmax:integer);//Before starting the download, set the PROGRESSBAR1 maximum value to receive the data size.
Begin
Progressbar1.max:=aworkcountmax;
progressbar1.min:=0;
progressbar1.position:=0;
End

Procedure Tform1.idhttp1work (Sender:tobject; Aworkmode:tworkmode;
const aworkcount:integer);//When the data is received, the progress will be displayed in ProgressBar1.
Begin
Progressbar1.position:=progressbar1.position+aworkcount;
End


Idhttp1get also has the form of getting strings: for example, the above can be rewritten as:

Procedure Tform1.button1click (Sender:tobject);
Var
mystr:string;
Begin
The idantifreeze1.onlywhenidle:=false;//settings make a response.
Try
Mystr:=idhttp1.get (' http://www.138soft.com/default.htm ');
Except
ShowMessage (' Network error! ');
Exit;
End
ShowMessage (MYSTR);
End

Source: http://hi.baidu.com/yuqingtan/blog/item/a9771c3d793cb6f73c6d9737.html

http://www.vckbase.com/module/articleContent.php?id=4385

Delphi 7 uses Idhttp crawl Web page to solve the phenomenon of suspended animation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.