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