我写了个线程,经测试可用.
unitdo
wnUnit;
interface
uses
Classes,SysUtils,IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP;
type
TDownThread = class(TThread)
private
{ Private declarations }
FURL:string;
protected
procedure Execute;
override;
public
constructor Create(url:string);
end;
implementation
{ TDownThread }
constructor TDownThread.Create(url: string);
begin
FURL:=url;
inherited Create(false);
end;
procedure TDownThread.Execute;
var ms:TMemoryStream;
Idh: TIdHTTP;
s,v:string;
ts:TStringList;
begin
{ Place thread code here }
FreeOnTerminate:=true;
ms:=TMemoryStream.Create;
idh:=TidHttp.Create(nil);
try
try
Idh.Get(FURL,ms);
except
exit;
end;
if ms.Size = 0 then
exit;
ms.Position := 0;
if pos('.gif',FURL)>0 then
begin
ms.SaveToFile('c:/test.gif');
exit;
end;
finally
idh.Free;
ms.Free;
end;
end;
end.
------------------------------------------
使用:
TDownThread.Create('http://www2.79wx.com/2006-3/2/20063222242463641.gif');
然后在C盘找找test.gif吧.