Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  dwnloader
Language: PASCAL
Code:
library downloader

uses
uses WinInetmm;


function DownloadFile(const UserAgent, URL, FileName: string): boolean;
const
  BUF_SIZE = 4096;
var
  hInet, hURL: HINTERNET;
  f: file;
  buf: PByte;
  amtc: cardinal;
  amti: integer;
begin
  result := false;
  hInet := InternetOpen(PChar(UserAgent), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  try
    hURL := InternetOpenUrl(hInet, PChar(URL), nil, 0, 0, 0);
    try
      GetMem(buf, BUF_SIZE);
      try
        FileMode := fmOpenWrite;
        AssignFile(f, FileName);
        try
          Rewrite(f, 1);
          repeat
            InternetReadFile(hURL, buf, BUF_SIZE, amtc);
            BlockWrite(f, buf^, amtc, amti);
          until amtc = 0;
          result := true;
        finally
          CloseFile(f);
        end;
      finally
        FreeMem(buf);
      end;
    finally
      InternetCloseHandle(hURL);
    end;
  finally
    InternetCloseHandle(hInet);
  end;
end;

begin
end.     
Comments: