Mega Code Archive

 
Categories / Delphi / Examples
 

How to download a file from 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://go.to/masdp', 'c:\index.html', 0, nil) <> 0 then MessageBox(Handle, 'An error ocurred while downloading the file.', PChar(Application.Title), MB_ICONERROR or MB_OK);