先
uses ..., ExtActns, ...;
Tform1 = class(TForm)
...
procedure URL_OnDownloadProgress (Sender: TDownLoadURL; Progress, ProgressMax: Cardinal; StatusCode: TURLDownloadStatus; StatusText: String; var Cancel: Boolean);
...
private
{ Private declarations }
public
{ Public declarations }
end;
procedure Tform1.URL_OnDownloadProgress (Sender: TDownLoadURL; Progress, ProgressMax: Cardinal; StatusCode: TURLDownloadStatus; StatusText: String; var Cancel: Boolean);
begin
ProgressBar.Max:= ProgressMax;
ProgressBar.Position:= Progress;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
with TDownloadURL.Create(self) do
begin
try
Screen.Cursor := crHourGlass;
URL := 'http://要下載的檔案網址';
// 要存放在本地端的資料夾及檔名, 在本例為存放在與程式同一資料夾下, 檔名為 test.jpg
FileName := getCurrentDir + '\test.jpg';
OnDownloadProgress := URL_OnDownloadProgress;
ExecuteTarget(nil);
end;
finally
Free;
ProgressBar.Position := 0;
Screen.Cursor := crDefault;
end;
end;
end;
所以若是每次都要下載最新內容的檔案, 則可在下載網址後再加上一個任意產生的參數, 如:
URL := 'http://www.domain.com/test.jpg?param=' + FormatDateTime('yyyymmddhhnnss', now);
加上一個格式為 "年月日時分秒" 的時間參數, 這樣就會下載最新內容的檔案了.
同理, 在寫 client 端的 javascript 網頁程式時, 也可運用此方法 → 加上一個任意產生的參數.
沒有留言:
張貼留言