How to Download a File From the Internet

You can always use some component. But if you are just going to download there is no need to do this or to use ActiveX controls. Windows has the function you need already declared in the UrlMon.dll. To download a file to a local disk just use this code:

!!Note: This function is not described in Delphi Help nor in the Win32 Programmer’s Reference.

uses
  URLMon;
...
if URLDownloadToFile(nil, 'http://www.delphifaq.net/index.php',
  'C:\\HTML\\MDF\\index.php', 0, nil) <> 0 then
  MessageBox(Handle, 'An error ocurred while downloading the file.',
    PChar(Application.Title), MB_ICONERROR or MB_OK);

Tags: , , , , , , , , , , , , , , , , , ,

No Comments Yet

You can be the first to comment!

Leave a comment

OpenID Login

Standard Login