Try this:
http://delphi.about.com/cs/adptips2003/a/bltip0903_2.htm
~~~~~~~~~~~~~~~~~~~~~~~~~
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
}
~~~~~~~~~~~~~~~~~~~~~~~~~
Glenn B. Lawler wrote:
David,
Thanks for the info on URLDownloadToFile. I had not used that one before.
Long ago
wrote a Delphi function that calls WinINet API functions to downloading a
URL.
I have been using that for a long time and it works great. This seems
to be
a single
call that does the same thing.
By the way, in case anyone is interested, I translated your VB header
to a
Delphi header:
function URLDownloadToFile(pCaller: pointer; szURL: PChar; szFileName:
PChar; dwReserved: DWORD; lpfnCB: pointer): Longint; stdcall; external
'urlmon.dll' name 'URLDownloadToFileA';
I also wrote a Delphi wrapper function that dynamically loads the
library.
If anyone is interested,
let me know and I will post.
The reason I for my question is that I am looking for a simple way to
provide a download
that shows progress. My understanding is that DoFileDownload basically
invokes the
same download progress dialog used by Internet Explorer.
I could write my own, but do so I would need to figure out how to get the
file size from the
web server.
Thanks again,
Glenn Lawler
www.incodesystems.com
-----Original Message-----
From: burkleyd [SMTP:burkl...@yahoo.com <mailto:burkleyd%40yahoo.com>]
Sent: Wednesday, April 08, 2009 3:30 PM
To: advanced_delphi@yahoogroups.com
<mailto:advanced_delphi%40yahoogroups.com>
Subject: [advanced_delphi] Re: Prototype for DoFileDownload in shdocvw.dll
--- In advanced_delphi@yahoogroups.com
<mailto:advanced_delphi%40yahoogroups.com>, "Glenn Lawler" <gblaw...@...>
wrote:
>
> I have translated the prototype for DoFileDownload from VB to Delphi as
follows:
>
> VB:
> Private Declare Function DoFileDownload Lib "shdocvw" (ByVal
lpszFile As
String)
> As Long
>
> Delphi:
> function DoFileDownload(lpszFile: PChar): Longint; far; external
'shdocvw.dll';
>
> When I call it, I get a warning dialog "Download could not complete"
with
a
> series of unprintable characters followed by the word "from".
> The program is then apparently closed by Windows.
>
> As I understand this call, lpszFile is the URL to download.
>
> Thought it might be a widestring, so redefined as:
> function DoFileDownload(lpszFile: PWideChar): Longint; far; external
> 'shdocvw.dll';
>
> No joy.
>
> Anyone have a very simple working example that makes this call?
>
> Thanks,
>
> Glenn Lawler
> www.incodesystems.com
>
Hi Glenn,
I don't know if you're aware that...
DoFileDownload is dependent on the security
settings of the users Internet Explorer.
So it "may" or "may not" cause problems.
Another API function that might be better is...
Declare Function URLDownloadToFile _
Lib "urlmon" Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, ByVal szURL As String, _
ByVal szFileName As String, ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
In another programming language that I use,
I've had success calling it by using...
Dim sUrl As String
sUrl = "www.yahoo.com"
Dim sLocalFile As String
sLocalFile = "c:\temp\yahoo_index.html"
Dim lRet As Long
lRet = URLDownloadToFile(0, sURL, sLocalFile, 0, 0)
If lRet = 0 (zero) the download was successful.
The downloaded file will be in the folder that
you specified.
David