Delphi从Internet下载文件
生活随笔
收集整理的這篇文章主要介紹了
Delphi从Internet下载文件
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Delphi從Internet下載文件
今天在做拍賣系統(tǒng)的時(shí)候,因考慮到網(wǎng)絡(luò)狀況問題,需要將拍品所有信息下載到本機(jī),包括拍品圖片,因此需要實(shí)現(xiàn)從Internet下載文件的功能。????? 下面是代碼片段: privatefunction 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;varhasError: boolean;beginhasError:=false;with TDownloadURL.Create(self) dotryURL:=SourceFile;FileName := DestFile;OnDownloadProgress := URL_OnDownloadProgress;ExecuteTarget(nil) ;except on e: Exception do beginFormMain.SetStatusInfo(e.Message);Free;hasError:=true;end;end;Result := not hasError;end;procedure TFrameChannel.URL_OnDownloadProgress;beginApplication.ProcessMessages;end;調(diào)用時(shí):ofname:='http://www.aaa.com/a.jpg';nfname:='images\.jpg';if not DownloadFile(ofname, nfname) then showMessage('Error')endshowMessage('OK');
?
????? 注:以上程序在大文件下載過程不會(huì)死鎖,而且你可以在URL_OnDownloadProgress函數(shù)中用參數(shù)來處理自已的進(jìn)度條以顯示下載進(jìn)度。因?yàn)槲业某绦虿恍枰?#xff0c;所以沒有寫出來。
轉(zhuǎn)載于:https://www.cnblogs.com/china1/p/3395100.html
總結(jié)
以上是生活随笔為你收集整理的Delphi从Internet下载文件的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 线程安全且高效的单例
- 下一篇: 系统集成资质培训 - 标准系列 -软件文