Delphi从Internet下载文件

 今天在做拍卖系统的时候,因考虑到网络状况问题,需要将拍品所有信息下载到本机,包括拍品图片,因此需要实现从Internet下载文件的功能。

      下面是代码片段:
 1  dot.gifdot.gif..
 2 
 3     private
 4      function DownloadFile(SourceFile, DestFile:  string ): Boolean;
 5      procedure URL_OnDownloadProgress(Sender: TDownLoadURL;
 6            Progress, ProgressMax: Cardinal;
 7            StatusCode: TURLDownloadStatus;
 8            StatusText: String; var Cancel: Boolean) ;
 9      { Private declarations }
10 
11  dot.gifdot.gif.
12 
13  function TFrameChannel.DownloadFile(SourceFile, DestFile:  string ): Boolean;
14  var
15    hasError: boolean;
16  begin
17    hasError: = false ;
18    with TDownloadURL.Create(self)  do
19     try
20      URL: = SourceFile;
21      FileName : =  DestFile;
22      OnDownloadProgress : =  URL_OnDownloadProgress;
23      ExecuteTarget(nil) ;
24    except on e: Exception  do  begin
25      FormMain.SetStatusInfo(e.Message);
26      Free;
27      hasError: = true ;
28      end;
29    end;
30    Result : =  not hasError;
31  end;
32 
33  procedure TFrameChannel.URL_OnDownloadProgress;
34  begin
35     Application.ProcessMessages;
36  end;
37 
38  调用时:
39      ofname: = ' http://www.aaa.com/1.jpg ' ;
40      nfname: = ' images\1.jpg ' ;
41       if  not DownloadFile(ofname, nfname) then 
42        showMessage( ' Error ' )
43      end
44        showMessage( ' OK ' );
45 


      注:以上程序在大文件下载过程不会死锁,而且你可以在URL_OnDownloadProgress函数中用参数来处理自已的进度条以显示下载进度。因为我的程序不需要,所以没有写出来。

http://www.cnblogs.com/taobataoma/archive/2007/04/17/717174.html

转载于:https://www.cnblogs.com/sunsoft/archive/2011/02/26/1965635.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值