Delphi从Internet下载文件
2013-10-29 20:39
309 查看
Delphi从Internet下载文件
今天在做拍卖系统的时候,因考虑到网络状况问题,需要将拍品所有信息下载到本机,包括拍品图片,因此需要实现从Internet下载文件的功能。
下面是代码片段:
注:以上程序在大文件下载过程不会死锁,而且你可以在URL_OnDownloadProgress函数中用参数来处理自已的进度条以显示下载进度。因为我的程序不需要,所以没有写出来。
今天在做拍卖系统的时候,因考虑到网络状况问题,需要将拍品所有信息下载到本机,包括拍品图片,因此需要实现从Internet下载文件的功能。
下面是代码片段:
private function DownloadFile(SourceFile, DestFile: string): Boolean; procedure URL_OnDownloadProgress(Sender: TDownLoadURL; Progress, ProgressMax: Cardinal; StatusCode: TURLDownloadStatus; StatusText: String; var Cancel: Boolean) ; { Private declarations } . function TFrameChannel.DownloadFile(SourceFile, DestFile: string): Boolean; var hasError: boolean; begin hasError:=false; with TDownloadURL.Create(self) do try URL:=SourceFile; FileName := DestFile; OnDownloadProgress := URL_OnDownloadProgress; ExecuteTarget(nil) ; except on e: Exception do begin FormMain.SetStatusInfo(e.Message); Free; hasError:=true; end; end; Result := not hasError; end; procedure TFrameChannel.URL_OnDownloadProgress; begin Application.ProcessMessages; end; 调用时: ofname:='http://www.aaa.com/a.jpg'; nfname:='images\.jpg'; if not DownloadFile(ofname, nfname) then showMessage('Error') end showMessage('OK');
注:以上程序在大文件下载过程不会死锁,而且你可以在URL_OnDownloadProgress函数中用参数来处理自已的进度条以显示下载进度。因为我的程序不需要,所以没有写出来。
相关文章推荐
- Delphi从Internet下载文件
- Delphi从Internet下载文件
- 封装Ftp API函数,实现上传,下载文件,创建目录(Delphi)
- delphi上传下载整个目录文件
- 使用wininetAPI下载internet文件的源码
- 用delphi 实现文件下载,可以用于软件的升级
- Delphi 获取Internet缓存文件 -- FindFirstUrlCacheEntry FindNextUrlCacheEntry
- Delphi XE2 DataSnap 上传下载文件
- 解决InternetReadFile下载带有中文字符的文件失败的方案
- 使用 CInternetSession 封装多线程 http 文件下载
- Delphi实现文件下载的几种方法
- delphi 文件下载汇总
- delphi下载文件,delphi从http服务器上下载文件
- delphi 从http 上下载文件的几种方法
- 如何从Internet上有效而稳定地下载文件
- delphi IdHTTP实现Get方法下载文件,断点续传
- 用Delphi实现文件下载的几种方法
- delphi 文件下载汇总delphi多线程超时控
- DELPHI TDownLoadURL下载网络文件
- Delphi IdHTTP1下载文件防止假死 (