[delphi]代码库
/// <summary>显示一个下载进度对话框</summary>
/// <param name="aform">一个form或者frame</param>
/// <param name="aURL">要下载文件的url地址</param>
/// <param name="SaveToFile">要保存的文件全路径</param>
/// <param name="aProc">一个回调函数TProc<String, TaDownLoadDialogFunctionResult></param>
/// <param name="aProgressColor">进度条的颜色</param>
/// <param name="cancancel">取消下载按钮是否可见</param>
procedure ShowDownLoadDialog(aform: TComponent; AUrl, SaveToFile: String;
aProc: TProc<String, TaDownLoadDialogFunctionResult> = nil;
aProgressColor: TAlphaColor = $FFA5D34D; cancancel: boolean = True);
示例
procedure TFormGY.Rectangle79MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; x, y: Single);
var
apkfileurl, SaveToFile: string;
begin
if Sqrt(Sqr(abs(x - X1)) + Sqr(abs(y - Y1))) > 5 then // 防止鼠标单击时与滑动冲突
exit;
// 如果显示了提示框,则不执行后面的代码,提示框只会主动显示一次
if SJGY.ShowHint(self, Sender, '这是一个通用的下载进度对话框,下载完毕后会执行您指定的事件。') = true then
exit;
SJGY.RootUrl := 'http://117.34.118.7:94/';
apkfileurl := SJGY.RootUrl + 'nosessionhtmls/shengjiwenjian/YiDongTongYongKuangJiaAPP.rar';
SaveToFile := SJGY.GetHuanCunPath('temp') + 'YiDongTongYongKuangJiaAPP.rar';
SJGY.ShowDownLoadDialog(self, apkfileurl, SaveToFile,
procedure(aResult: string; aDownLoadDialogFunctionResult: TaDownLoadDialogFunctionResult)
begin
if aDownLoadDialogFunctionResult.Success = true then // 下载成功了
begin
SJGY.ShowDialog(self, '下载成功了,文件保存在:' + SaveToFile);
end
else
begin
SJGY.ShowDialog(self, '下载失败:' + aDownLoadDialogFunctionResult.ErrorMessage);
end;
end); // $FFF7946F 可以设置进度条的颜色
end;