procedure TForm1.Button1Click(Sender: TObject);
var
MyStream:TMemoryStream;
begin
IdAntiFreeze1.OnlyWhenIdle:=False;//設置使程序有反應.
MyStream:=TMemoryStream.Create;
try
IdHTTP1.Get('http://www.appcontrols.com/demos/exe/HTTPDemo.exe',MyStream);
except
Showmessage('沒有下載成功!');
MyStream.Free;
Exit;
end;
MyStream.SaveToFile(ExtractFilePath(paramstr(0))+'HTTPDemo.zip');
MyStream.Free;
Showmessage('OK');
end;
procedure TForm1.IdHTTP1WorkBegin(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCountMax: Integer);
begin
//開始下載前,將ProgressBar1的最大值設置為需要接收的數據大小.
ProgressBar1.Max:=AWorkCountMax;
ProgressBar1.Min:=0;
ProgressBar1.Position:=0;
end;
procedure TForm1.IdHTTP1Work(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCount: Integer);
begin
//接收數據的時候,進度將在ProgressBar1顯示出來.
ProgressBar1.Position:=ProgressBar1.Position+AWorkCount;
end;