Delphi 使用idhttp下載显示进度以及大小

转自: http://www.delphitop.com/html/kongjian/2528.html

Delphi 使用idhttp下載显示进度以及大小_第1张图片

在更新程式時,需要知道目前下載到多少百分比及大小怎麼做?

Delphi使用idhttp及IdAntiFreeze(防止程式看起來當掉)二個元件就可以做得到。順便列下關鍵程式碼

procedure TForm1 . BtnDownloadClick(Sender: TObject);
var
   tStream: TMemoryStream;
begin
   tStream := TMemoryStream . Create;
   try
     IdHTTP1 . Get(EdtSource . Text, tStream);
     tStream . SaveToFile(EdtTarget . Text);
     ShowMessage( 'Download Success!' );
   except
     ShowMessage( 'Download Fail!' );
   end ;
   tStream . Free;
end ;
 
procedure TForm1 . IdHTTP1Work(ASender: TObject; AWorkMode: TWorkMode;
   AWorkCount: Int64 );
begin
   Label1 . Caption := BytesToStr(aWorkCount);
   ProgressBar1 . Position := aWorkCount;
   <a title="Update" href="http: //superlevin.ifengyuan.tw/tag/update/">Update</a>;
end ;
 
procedure TForm1 . IdHTTP1WorkBegin(ASender: TObject; AWorkMode: TWorkMode;
   AWorkCountMax: Int64 );
begin
   ProgressBar1 . Max := aWorkCountMax;  // Set File total size
   Label2 . Caption := BytesToStr(aWorkCountMax);
   Update;

end;


代码:http://pan.baidu.com/s/1kp9hs



你可能感兴趣的:(Delphi 使用idhttp下載显示进度以及大小)