Http://www.net.com.cn/eschool/inforcenter/a20040429306316.htmlunit unit1;
Interface
Uses Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls, Shellapi, Urlmon;
type TForm1 = class (TForm) Button1: TButton; procedure Button1Click (Sender: TObject); private {Private declarations} function DownloadFile (Source, Dest: string): Boolean; public {Public declarations} end;
Var Form1: TFORM1;
IMPLEMENTATION
{$ R * .dfm}
Procedure TForm1.Button1Click (Sender: TOBJECT); Begin if Downloadfile ('http://cc.hbu.edu.cn/jackfan/wbx.exe', 'c: /rd.exe') Then ShowMessage ('Download Succesful " Else ShowMessage ('Download unsuccesful');
Function TFORM1.DOWNLOADFILE (SOURCE, DEST: STRING): Boolean; Begin Try Result: = URLDOWNLOADTOFILE (NIL, PCHAR (SOURCE), PCHAR (DEST), 0, NIL) = 0; ExcePt Result: = false; end;
end Examples of two: Uses URLMon, ShellApi; function DownloadFile (SourceFile, DestFile: string):. Boolean; begin try Result: = UrlDownloadToFile (nil, PChar (SourceFile), PChar (DestFile), 0, nil) = 0; except Result : = False; end; end; procedure tform1.button1.click (sender: TOBJECT); const // URL location sourcefile: = 'http://www.google.com/intl/de/images/home_title.gif'; // Where to save the file DestFile: = 'c: /temp/google-image.gif'; begin if DownloadFile (SourceFile, DestFile) then begin ShowMessage ( 'Download succesful!'); // Show downloaded image in your browser ShellExecute (Application.Handle, PChar ( 'open'), PChar (DestFile), PChar ( ''), nil, SW_NORMAL) end else ShowMessage ( 'Error while downloading' SourceFile) end; NMHTTP1.InputFileMode control may also be used NMHTTP : = TURE; NMHTTP1.BODY: = 'Local file name'; nmhttp1.header: = 'head.txt'; nmhttp1.outputfilemode: = false; nmhttp1.reportlevel: = status_basic; nmhttp1.proxy: = 'proxy server IP Address'; NMHTTP1.PROXY Port: = 'proxy server port number'; with nmhttp1.headerinfo do beg cookie: = ''; localmailaddress: = '; localprogram: =' '; referer: ='; userid: = 'User Name'; Password : = 'User password'; end; nmhttp1.get ('http://www.abcdefg.com/software/a.zip'); try, there is an example of TNMHTTP control in Delphi's directory. NT4 , WIN95 , IE3 , you can use the URL Moniker function. Uses Urlmon; ... Olecheck (NIL, 'URL', 'FileName', 0, NIL); where the last parameter you can also pass to the implementation of IbindStatusCallback to track download schedule or control abort download. A simple occasion is done.