Delphi用TActionList實(shí)現(xiàn)下載文件的方法
Delphi中的TActionList有個(gè)標(biāo)準(zhǔn)動(dòng)作TDownLoadURL,內(nèi)部是使用的URLDownloadToFile,它下載文件時(shí)會(huì)定時(shí)產(chǎn)生OnDownloadProgress 事件,這樣就可以用進(jìn)度條顯示。
本文講述了Delphi用TActionList實(shí)現(xiàn)下載文件的方法,實(shí)現(xiàn)代碼如下所示:
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtActns, ActnList, StdCtrls, ComCtrls; type TForm1 = class(TForm) Button1: TButton; ActionList1: TActionList; ProgressBar1: TProgressBar; procedure Button1Click(Sender: TObject); private { Private declarations } procedure URL_OnDownloadProgress (Sender: TDownLoadURL; Progress, ProgressMax: Cardinal; StatusCode: TURLDownloadStatus; StatusText: String; var Cancel: Boolean) ; public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure Tform1.URL_OnDownloadProgress; begin ProgressBar1.Max:= ProgressMax; ProgressBar1.Position:= Progress; end; procedure TForm1.Button1Click(Sender: TObject); begin with TDownloadURL.Create(self) do try URL:='http://chabaoo.cn/images/logo.gif'; FileName := 'logo.gif'; OnDownloadProgress := URL_OnDownloadProgress; ExecuteTarget(nil) ; finally Free; end; showMessage('OK'); ProgressBar1.Max := 0; end;
相關(guān)文章
Java中CountDownLatch和CyclicBarrier的區(qū)別與詳解
CountDownLatch和CyclicBarrier是Java并發(fā)包提供的兩個(gè)非常易用的線程同步工具類,本文主要介紹了Java中CountDownLatch和CyclicBarrier的區(qū)別與詳解,具有一定的參考價(jià)值,感興趣的可以了解一下2023-11-11Delphi實(shí)現(xiàn)木馬文件傳輸代碼實(shí)例
這篇文章主要介紹了Delphi實(shí)現(xiàn)木馬文件傳輸?shù)姆椒?對(duì)于了解木馬的運(yùn)行原理有一定的幫助,需要的朋友可以參考下2014-07-07Delphi創(chuàng)建開機(jī)啟動(dòng)項(xiàng)的方法示例
這篇文章主要介紹了Delphi創(chuàng)建開機(jī)啟動(dòng)項(xiàng)的方法,很有實(shí)用價(jià)值,需要的朋友可以參考下2014-07-07