我要实现下载给定url的目标文件,怎么做?
我用api函数internetopen,internetopenurl,internetreadfile.等几个函数可以做,但是太烦了,又没有简单的方法?

解决方案 »

  1.   

    uses ShellAPI;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
      ShellExecute(0, 'open', 'http://www9.pconline.com.cn/pcgames/gamedown.php?id=14446', '', '', SW_SHOW);
    end;—————————————————————————————————
    宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
    —————————————————————————————————
      

  2.   

    你这个是打开url呀,不是我要的。
      

  3.   

    你怎么这么笨呢?你给定一个远程文件的url不就是下载了吗?
    —————————————————————————————————
    宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
    —————————————————————————————————
      

  4.   

    同意楼上的,如果你给定一个远程文件的url就直接使用Windows自己的下载下载你给定的文件,如果你想要写一个下载文件的程序的话,那么你只有从HTTP/FTP协议入手了,可能花费时间会比较长,代码量也非常大
      

  5.   

    用URLDownloadToFile这个API
    用法可以查看MSND给分吧
      

  6.   

    Downloads bits from the Internet and saves them to a file.SyntaxHRESULT URLDownloadToFile(          LPUNKNOWN pCaller,
        LPCTSTR szURL,
        LPCTSTR szFileName,
        DWORD dwReserved,
        LPBINDSTATUSCALLBACK lpfnCB
    );
    ParameterspCaller
    Pointer to the controlling IUnknown interface of the calling Microsoft® ActiveX® component (if the caller is an ActiveX component). If the calling application is not an ActiveX component, this value can be set to NULL. Otherwise, the caller is a Component Object Model (COM) object that is contained in another component (such as an ActiveX control within the context of an HTML page). This parameter represents the outermost IUnknown of the calling component. The function attempts the download within the context of the ActiveX client framework and allows the caller's container to receive callbacks on the progress of the download. 
    szURL
    Pointer to a string value containing the URL to be downloaded. Cannot be set to NULL. 
    szFileName
    Pointer to a string value containing the name of the file to create for bits that come from the download. 
    dwReserved
    Reserved. Must be set to 0.
    lpfnCB
    Pointer to the caller's IBindStatusCallback interface. URLDownloadToFile calls this interface's IBindStatusCallback::OnProgress method on a connection activity, including the arrival of data. IBindStatusCallback::OnDataAvailable is never called. Implementing IBindStatusCallback::OnProgress allows a caller to implement a user interface or other progress monitoring functionality. It also allows the download operation to be canceled by returning E_ABORT from the IBindStatusCallback::OnProgress call. This can be set to NULL. 
    Return ValueReturns one of the following values.E_OUTOFMEMORY The buffer length is invalid or there was insufficient memory to complete the operation. 
    S_OK The operation succeeded. 
    ResThe client can choose to be notified of progress through a notification callback.Function InformationHeader Urlmon.h 
    Import library Urlmon.lib 
    Minimum availability Internet Explorer 3.0 
    Minimum operating systems Windows NT 4.0, Windows 95 
      

  7.   

    再给你一个用法
    例如,你要下载某一网址内存到一文件,可以这样写
    URLDownloadToFile(szURL,szFileName,0,nil);我没试过,应该是这样如果不行,你把nil改为NULL就行了保证能用
      

  8.   

    uses Wininet; 

    function GetInetFile (const fileURL, FileName: String): boolean;
    const BufferSize = 1024; 
    var 
      hSession, hURL: HInternet; 
      Buffer: array[1..BufferSize] of Byte; 
      BufferLen: DWORD; f: File; 
      sAppName: string; 
    begin 
      Result:=False; 
      sAppName := ExtractFileName(Application.ExeName); 
      hSession := InternetOpen(PChar(sAppName), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0); 
      try 
         hURL := InternetOpenURL(hSession, PChar(fileURL), nil,0,0,0); 
        try 
           AssignFile(f, FileName); Rewrite(f,1); 
          repeat 
             InternetReadFile(hURL, @Buffer, SizeOf(Buffer), BufferLen);
             BlockWrite(f, Buffer, BufferLen) 
          until BufferLen = 0; 
           CloseFile(f); 
           Result:=True; 
        finally 
          InternetCloseHandle(hURL) 
        end 
      finally 
        InternetCloseHandle(hSession) 
      end 
    end; 
    ***********************************
    var 
      FileOnNet, LocalFileName: string 
    begin 
      FileOnNet:= 'http://delphi.about.com/library/netfile.zip'; 
      LocalFileName:='netfile.zip'; 
      if GetInetFile(FileOnNet,LocalFileName)=True then 
         ShowMessage('下载成功!') 
      else 
         ShowMessage('下载失败!') 
    end;
      

  9.   

    uses Wininet; 

    function GetInetFile (const fileURL, FileName: String): boolean;
    const BufferSize = 1024; 
    var 
      hSession, hURL: HInternet; 
      Buffer: array[1..BufferSize] of Byte; 
      BufferLen: DWORD; f: File; 
      sAppName: string; 
    begin 
      Result:=False; 
      sAppName := ExtractFileName(Application.ExeName); 
      hSession := InternetOpen(PChar(sAppName), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0); 
      try 
         hURL := InternetOpenURL(hSession, PChar(fileURL), nil,0,0,0); 
        try 
           AssignFile(f, FileName); Rewrite(f,1); 
          repeat 
             InternetReadFile(hURL, @Buffer, SizeOf(Buffer), BufferLen);
             BlockWrite(f, Buffer, BufferLen) 
          until BufferLen = 0; 
           CloseFile(f); 
           Result:=True; 
        finally 
          InternetCloseHandle(hURL) 
        end 
      finally 
        InternetCloseHandle(hSession) 
      end 
    end; 
    ***********************************
    var 
      FileOnNet, LocalFileName: string 
    begin 
      FileOnNet:= 'http://delphi.about.com/library/netfile.zip'; 
      LocalFileName:='netfile.zip'; 
      if GetInetFile(FileOnNet,LocalFileName)=True then 
         ShowMessage('下载成功!') 
      else 
         ShowMessage('下载失败!') 
    end;
      

  10.   

    uses Wininet; 

    function GetInetFile (const fileURL, FileName: String): boolean;
    const BufferSize = 1024; 
    var 
      hSession, hURL: HInternet; 
      Buffer: array[1..BufferSize] of Byte; 
      BufferLen: DWORD; f: File; 
      sAppName: string; 
    begin 
      Result:=False; 
      sAppName := ExtractFileName(Application.ExeName); 
      hSession := InternetOpen(PChar(sAppName), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0); 
      try 
         hURL := InternetOpenURL(hSession, PChar(fileURL), nil,0,0,0); 
        try 
           AssignFile(f, FileName); Rewrite(f,1); 
          repeat 
             InternetReadFile(hURL, @Buffer, SizeOf(Buffer), BufferLen);
             BlockWrite(f, Buffer, BufferLen) 
          until BufferLen = 0; 
           CloseFile(f); 
           Result:=True; 
        finally 
          InternetCloseHandle(hURL) 
        end 
      finally 
        InternetCloseHandle(hSession) 
      end 
    end; 
    ***********************************
    var 
      FileOnNet, LocalFileName: string 
    begin 
      FileOnNet:= 'http://delphi.about.com/library/netfile.zip'; 
      LocalFileName:='netfile.zip'; 
      if GetInetFile(FileOnNet,LocalFileName)=True then 
         ShowMessage('下载成功!') 
      else 
         ShowMessage('下载失败!') 
    end;
      

  11.   

    不给分
    下次不给回答了KAO
      

  12.   

    URLDownloadToFile (nil, szURL, szFileName, 0, nil);
      

  13.   

    xikug(西方不敢很帅) ,你说的这个URLDownloadToFile (nil, szURL, szFileName, 0, nil);
    要用到那个单元呀?