凯发k8天生赢家一触即发

delphi从internet下载文件 -凯发k8天生赢家一触即发

2023-08-12,,

delphi从internet下载文件

 

今天在做拍卖系统的时候,因考虑到网络状况问题,需要将拍品所有信息下载到本机,包括拍品图片,因此需要实现从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下载文件的相关教程结束。

网站地图