type
TfrMain = class(TForm)
...
private
procedure URL_OnDownloadProgress
(Sender: TDownLoadURL;
Progress, ProgressMax: Cardinal;
StatusCode: TURLDownloadStatus;
StatusText: String; var Cancel: Boolean) ;
...
implementation
...
procedure TfrMain.URL_OnDownloadProgress;
begin
ProgressBar1.Max:= ProgressMax;
ProgressBar1.Position:= Progress;
end;
function DoDownload;
begin
with TDownloadURL.Create(self) do
try
URL:='http://z.about.com/6/g/delphi/b/index.xml';
FileName := 'c:\ADPHealines.xml';
OnDownloadProgress := URL_OnDownloadProgress;
ExecuteTarget(nil) ;
finally
Free;
end;
end;
{
Note:
URL property points to Internet
FileName is the local file
}
This is great but there is a problem.
When trying to download the same file again anew, it does not
download the file again. It grabs it from somewhere else and populates
the location even after you deleted from the location.
I downloaded an 8 meg file and then deleted it.
I went to download it again, it took only a second and the
entire file was there. Where did it come from?
And How do I force a download anew and/or overwrite the old one?
TIA
> I downloaded an 8 meg file and then deleted it.
> I went to download it again, it took only a second
> and the entire file was there. Where did it come from?
Internet Explorer's local cache. TDownloadURL uses WinInet internally
(specifically, the "URLDownloadToFileA" function), which is the same library
that Internet Explorer uses for its own internal work.
> How do I force a download anew and/or overwrite the old one?
TDownloadURL does not expose that functionality. You will have to use a
different URL library to download files with.
Gambit
"Remy Lebeau (TeamB)" <no....@no.spam.com> wrote in message
news:4816478e$1...@newsgroups.borland.com...
Hi,
Did you try to call WinInet.DeleteUrlCacheEntry(URL) before starting
your download ?
A.R.
"Adrien Reboisson" <adrien-want-no-s...@nospam.com> wrote in
message news:48172c3a$1...@newsgroups.borland.com...
> Sender: TDownLoadURL
> i do not know TDownloadURL
It is a standard TAction object that Borland/CodeGear provides.
> if in it is anywhere a property for a cache (as string)
There is not.
Gambit
function DownloadFile(const url: string; const destinationFileName: string):
boolean;
var
hInet: HINTERNET;
hFile: HINTERNET;
localFile: file;
buffer: array[1..65535] of Byte;
bytesRead: DWORD;
b: boolean;
begin
b := False;
hInet := WinInet.InternetOpen('MyFile', INTERNET_OPEN_TYPE_DIRECT, nil,
nil, 0);
if Assigned(hInet) then
begin
hFile := InternetOpenURL(hInet, PAnsiChar(url), nil, 0,
INTERNET_FLAG_PRAGMA_NOCACHE, 0);
if Assigned(hFile) then
begin
AssignFile(localFile, destinationFileName);
Rewrite(localFile, 1);
bytesRead := 0;
repeat
InternetReadFile(hFile, @buffer, SizeOf(buffer), bytesRead);
BlockWrite(localFile, buffer, bytesRead);
until bytesRead = 0;
CloseFile(localFile);
InternetCloseHandle(hFile);
end;
InternetCloseHandle(hInet);
b := true;
end;
DownloadFile := b;
end;
...