在更新程式時,需要知道目前下載到多少百分比及大小怎麼做?
在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;
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
Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号
执行时间: 0.057855129241943 seconds