function DownloadFile(
const url:
string;
const destinationFileName:
string): boolean;
var
hInet: HINTERNET;
hFile: HINTERNET;
localFile:
File;
buffer:
array[1..1024]
of byte;
bytesRead: DWORD;
begin
result := False;
hInet := InternetOpen(PChar(application.title),
INTERNET_OPEN_TYPE_PRECONFIG,
nil,
nil,0);
hFile := InternetOpenURL(hInet,PChar(
url),
nil,0,0,0);
if Assigned(hFile)
then
begin
AssignFile(localFile,destinationFileName);
Rewrite(localFile,1);
repeat
InternetReadFile(hFile,@buffer,SizeOf(buffer),bytesRead);
BlockWrite(localFile,buffer,bytesRead);
until bytesRead = 0;
CloseFile(localFile);
result := true;
InternetCloseHandle(hFile);
end;
InternetCloseHandle(hInet);
end;