How to download from Delphi?

Asked

Viewed 1,219 times

2

Hi, I created an application on Delphi, but she needs to download some files I have on a website, but I have no idea how to do this, please help me. Thank you for reading my question!

1 answer

2


You can use the function URLDownloadToFile:

// Inclua em "Uses" a unit "Urlmon"
function BaixarArquivo(const URL, SalvarComo: string): Boolean;
var
  H: HRESULT;
begin
  H := URLDownloadToFile(nil, pchar(URL),
                              pchar(SalvarComo),
                              0,
                              nil);
  Result := H = S_OK;
end;

Example of use:

if BaixarArquivo('http://www.fooBAR.com/baz.poo', 'C:\baz.poo') then
  ShowMessage('Arquivo baixado com sucesso!')
else
  ShowMessage('Falha ao baixar arquivo.');

There is also how to do this with the component TIdHTTP with the method Get.

  • 1

    Thanks friend! This way it worked!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.