我做了一个下载的程序,用的是http下载的,我再用vclzip解压缩,结果在解压缩的过程中给我报了一个错:另一个进程正在使用我下载的那个文件,开始我以为我还没能下载完就执行解压,所以才报这个错,可是我看到我下载的程序的大小和我放在网上的大小是一样的。
致使我解压也没有成功。我怎么样判断我从网上下载文件已经完毕,且完毕后是否自动关闭相应的进程呢?
急!
   谢谢!

解决方案 »

  1.   

    http下载的完后要把和这个文件相关的东西关了,如字柄。你也可以用CopyFile拷贝一个临时的,再解压这个临时的文件也一样。
      

  2.   

    uses 
      URLMon, ShellApi; function DownloadFile(SourceFile, DestFile: string): Boolean; 
    begin 
      try 
        Result := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0, nil) = 0; 
      except 
        Result := False; 
      end; 
    end; procedure TForm1.Button1Click(Sender: TObject); 
    const 
      // URL Location 
      SourceFile = 'http://www.google.com/intl/de/images/home_title.gif'; 
      // Where to save the file 
      DestFile = 'c:\temp\google-image.gif'; 
    begin 
      if DownloadFile(SourceFile, DestFile) then 
      begin 
        ShowMessage('Download succesful!');  //处理完成
        // Show downloaded image in your browser 
        ShellExecute(Application.Handle, PChar('open'), PChar(DestFile), 
          PChar(''), nil, SW_NORMAL) 
      end 
      else 
        ShowMessage('Error while downloading ' + SourceFile) 
    end; 
      

  3.   

    2.} 
    uses 
      Wininet; function DownloadURL(const aUrl: string): Boolean; 
    var 
      hSession: HINTERNET; 
      hService: HINTERNET; 
      lpBuffer: array[0..1024 + 1] of Char; 
      dwBytesRead: DWORD; 
    begin 
      Result := False; 
      // hSession := InternetOpen( 'MyApp', INTERNET_OPEN_TYPE_DIRECT, nil, nil, 0); 
      hSession := InternetOpen('MyApp', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0); 
      try 
        if Assigned(hSession) then 
        begin 
          hService := InternetOpenUrl(hSession, PChar(aUrl), nil, 0, 0, 0); 
          if Assigned(hService) then 
            try 
              while True do 
              begin 
                dwBytesRead := 1024; 
                InternetReadFile(hService, @lpBuffer, 1024, dwBytesRead); 
                if dwBytesRead = 0 then break; 
                lpBuffer[dwBytesRead] := #0; 
                Form1.Memo1.Lines.Add(lpBuffer); 
              end; 
              Result := True; 
            finally 
              InternetCloseHandle(hService); 
            end; 
        end; 
      finally 
        InternetCloseHandle(hSession); 
      end; 
    end; {********************************************************} {3. Forces a download of the requested file, object, or directory listing from the origin server, 
        not from the cache 
    } function DownloadURL_NOCache(const aUrl: string; var s: String): Boolean; 
    var 
      hSession: HINTERNET; 
      hService: HINTERNET; 
      lpBuffer: array[0..1024 + 1] of Char; 
      dwBytesRead: DWORD; 
    begin 
      Result := False; 
      s := ''; 
      // hSession := InternetOpen( 'MyApp', INTERNET_OPEN_TYPE_DIRECT, nil, nil, 0); 
      hSession := InternetOpen('MyApp', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0); 
      try 
        if Assigned(hSession) then 
        begin 
          hService := InternetOpenUrl(hSession, PChar(aUrl), nil, 0, INTERNET_FLAG_RELOAD, 0); 
          if Assigned(hService) then 
            try 
              while True do 
              begin 
                dwBytesRead := 1024; 
                InternetReadFile(hService, @lpBuffer, 1024, dwBytesRead); 
                if dwBytesRead = 0 then break; 
                lpBuffer[dwBytesRead] := #0; 
                s := s + lpBuffer; 
              end; 
              Result := True; 
            finally 
              InternetCloseHandle(hService); 
            end; 
        end; 
      finally 
        InternetCloseHandle(hSession); 
      end; 
    end; //aufrufen 
    var 
      s: String; 
    begin 
     if DownloadURL('http://www.swissdelphicenter.ch/', s) then 
       ShowMessage(s); 
    end;