Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

DownLoad with Progress Bar

1,035 views
Skip to first unread message

JoJo

unread,
Apr 28, 2008, 4:24:48 PM4/28/08
to
uses ExtActns, ...

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


Remy Lebeau (TeamB)

unread,
Apr 28, 2008, 5:54:05 PM4/28/08
to

"JoJo" <joey_warren@knologydotnet> wrote in message
news:48163293$1...@newsgroups.borland.com...

> 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


JoJo

unread,
Apr 29, 2008, 8:13:55 AM4/29/08
to
Any suggestions on which URL library to use?

"Remy Lebeau (TeamB)" <no....@no.spam.com> wrote in message
news:4816478e$1...@newsgroups.borland.com...

Adrien Reboisson

unread,
Apr 29, 2008, 10:09:58 AM4/29/08
to
JoJo a écrit :

> Any suggestions on which URL library to use?

Hi,

Did you try to call WinInet.DeleteUrlCacheEntry(URL) before starting
your download ?

A.R.

JoJo

unread,
May 1, 2008, 8:53:29 AM5/1/08
to
No I did not, thanks for pointing that out.

"Adrien Reboisson" <adrien-want-no-s...@nospam.com> wrote in
message news:48172c3a$1...@newsgroups.borland.com...

B. Mahn

unread,
May 3, 2008, 4:36:24 AM5/3/08
to
i do not know TDownloadURL, but if in it is anywhere a property for a cache
(as string), set it to "no-cache" to force a new download and to overwrite
a possibly already existing target.

> Sender: TDownLoadURL

Remy Lebeau (TeamB)

unread,
May 5, 2008, 1:25:45 PM5/5/08
to

"B. Mahn" <bm...@bmahn.com> wrote in message
news:481c...@newsgroups.borland.com...

> 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


B. Mahn

unread,
May 5, 2008, 3:17:01 PM5/5/08
to

...
uses WinInet...
...

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;
...

0 new messages