Delphi文件下载程序组件

我需要Delphi的文件下载程序组件.你可以帮我吗?

解决方法

使用高级 URLDownloadToFile功能
uses UrlMon;

...

URLDownloadToFile(nil,'http://www.rejbrand.se/','C:\Users\Andreas Rejbrand\Desktop\index.html',nil);

或者,您可以使用WinInet函数轻松编写自己的下载程序函数,例如

uses WinInet;

...

hInet := Internetopen(PChar(UserAgent),INTERNET_OPEN_TYPE_PRECONfig,nil,0);
try
  hURL := InternetopenUrl(hInet,PChar('http://' + Server + Resource),0);
  try
    repeat
      InternetReadFile(hURL,@Buffer,SizeOf(Buffer),BufferLen);

      ...

在这里有很多示例代码.使用上面的搜索框.

更新

我写了一个小样本.您可能希望在自己的线程中执行此代码,并让它每10 kB左右进行一次ping操作,以便您可以为用户提供一些进度条.

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),0);
  try
    hURL := InternetopenUrl(hInet,PChar(URL),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;

相关文章

 从网上看到《Delphi API HOOK完全说明》这篇文章,基本上都...
  从网上看到《Delphi API HOOK完全说明》这篇文章,基本上...
ffmpeg 是一套强大的开源的多媒体库 一般都是用 c/c+&#x...
32位CPU所含有的寄存器有:4个数据寄存器(EAX、EBX、ECX和ED...
1 mov dst, src dst是目的操作数,src是源操作数,指令实现的...