Einzelnen Beitrag anzeigen

Daniel G
(Gast)

n/a Beiträge
 
#5

Re: Problem mit URLDownloadToFile

  Alt 2. Jan 2007, 15:43
Hm... Es gäbe da auch noch die Variante über InternetReadFile:

Delphi-Quellcode:
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;
Quelle: http://www.cryer.co.uk/brian/delphi/..._file_http.htm
  Mit Zitat antworten Zitat