1、在idhttp.OnWork事件裡加Application.ProcessMessages;
在窗體上放個idhttp控件,寫他的OnWork方法。
procedure TForm1.IdHTTP1Work(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCount: Integer);
begin
Application.ProcessMessages;
end;
2、
//在主窗體中定義一個線程類
type
TMyDownLoad=class(TThread)
protected
procedure Execute;override;
procedure Download;
end;
type
TFMain = class(TForm)
....
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;
procedure TMyDownLoad.Execute
begin
inherited;
Download;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
TMyDownLoad.Create(false);
end;
星期三, 11月 14, 2007
把idhttp寫成一個執行序
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言