关于把idhttp放到线程当中进行下载,主窗体仍就不能响应其他操做的问题。
cdsun 2006-04-09 11:12:11 把idhttp放到线程当中进行下载,主窗体仍就不能响应其他操做的问题。
不知道应该怎么解决。第一次用线程和idhttp研究了两天实在搞不定。还是来这里请教一下大家。
我把代码贴上
很简单的代码
unit1.pas
.....
.....
implementation
uses
download;
.....
....
procedure TForm1.Button1Click(Sender: TObject);
var
downloadTD:TMyDownLoad;
begin
downloadTD:=TMyDownLoad.Create(false);
end;
线程的代码如下:
interface
uses
Windows,Classes,Messages, SysUtils,Dialogs,idhttp;
type
TMyDownLoad = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
procedure DownLoad;
end;
implementation
procedure TMyDownLoad.Execute;
begin
{ Place thread code here }
if Terminated then exit;
Synchronize(Download);
end;
procedure TMyDownLoad.Download;
Var
UnitName,PathName:String;
MyStream:TMemoryStream;
filepath:string;
IDHTTP: TIDHttp;
begin
IDHTTP:= TIDHTTP.Create(nil);
MyStream:=TMemoryStream.Create;
try
IdHTTP.Get('http://127.0.0.1/aiyouasp/testcode/11.exe',MyStream);
except
showmessage('网络出错未能下载完成!');
MyStream.Free;
Exit;
end;
filepath:=ExtractFilePath(ParamStr(0));
MyStream.SaveToFile(filepath+'\DownLoadFiles\11.exe');
MyStream.Free;
showmessage('下载完成!');
end;
end.
我想问问为什么放到了线程和没有放到线程当中的效果是一样的?
是我哪里弄错了。大家多指教。