unit Downloading; interface const DONE=0; ERROR_TMPFILE_UNOPENED = 10; ERROR_UNABLE_INITILIZE_WININET = 11; ERROR_CANNOT_OPEN_URL = 12; ERROR_UNLOAD_FILE_FROM_URL = 13; function DownloadFromURL(a_URL:string; a_tmpfile:string):byte; implementation uses WinInet; function DownloadFromURL(a_URL:string; a_tmpfile:string):byte; const BUFSIZE = 8*1024; var l_f:file of byte; l_hNet, l_hURLFile: HINTERNET; l_BytesRead:longword; l_Buffer:array[0..BUFSIZE-1] of byte; begin {$I-} assignFile(l_f, a_tmpfile); rewrite(l_f); {$I+} if ioresult<>0 then begin result:=ERROR_TMPFILE_UNOPENED; EXIT; end; l_hNet:=InternetOpen('Download File', PRE_CONFIG_INTERNET_ACCESS,nil,nil,0); if not Assigned(l_hNet) then begin result:=ERROR_UNABLE_INITILIZE_WININET; closeFile(l_f); EXIT; end; l_hURLFile := InternetOpenUrl(l_hNet, PChar(a_Url), nil, 0, INTERNET_FLAG_RELOAD, 0); if not Assigned(l_hURLFile) then begin result:=ERROR_CANNOT_OPEN_URL; InternetCloseHandle(l_hNet); closeFile(l_f); EXIT; end; l_BytesRead:=0; while(true) do begin if not InternetReadFile(l_hUrlFile, @l_Buffer, sizeof(l_Buffer), l_BytesRead) then begin result:=ERROR_UNLOAD_FILE_FROM_URL; InternetCloseHandle(l_hUrlFile); InternetCloseHandle(l_hNet); closeFile(l_f); EXIT; end; if l_BytesRead>0 then Blockwrite(l_f,l_Buffer,l_BytesRead) else break; end; InternetCloseHandle(l_hUrlFile); InternetCloseHandle(l_hNet); closeFile(l_f); result:=DONE; end; end.