如果在delphi中实现 使用twebbrowser 不读缓存,而是直接从网页上下载啊
急!!!

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    uses WinINet;procedure ClearTempInternetFiles(RemCookies: boolean);
    var
      lpEntryInfo: PInternetCacheEntryInfo;
      hCacheDir: LongWord (*Handle*);
      dwEntrySize, dwLastError: LongWord;
    begin
      //Get size of first entry in dwEntrySize
      dwEntrySize := 0;
      FindFirstUrlCacheEntry(nil, TInternetCacheEntryInfo(nil^), dwEntrySize);  //Create structure that can hold entry
      GetMem(lpEntryInfo, dwEntrySize);
      try
        //Get first cache entry and handle to retrieve next entry, output url
        hCacheDir := FindFirstUrlCacheEntry(nil, lpEntryInfo^, dwEntrySize);
        if hCacheDir = 0 then
          exit;    if (hCacheDir <> 0) and
           ((lpEntryInfo^.CacheEntryType and NORMAL_CACHE_ENTRY) = NORMAL_CACHE_ENTRY) then
        begin
          if ((lpEntryInfo^.CacheEntryType and COOKIE_CACHE_ENTRY) = 0) or RemCookies then
          begin
            if FileExists(string(lpEntryInfo^.lpszLocalFileName)) then
              DeleteFile(string(lpEntryInfo^.lpszLocalFileName)); //delete file        DeleteUrlCacheEntry(lpEntryInfo^.lpszSourceUrlName);
          end;
        end;
      finally
        //free structure
        FreeMem(lpEntryInfo);
      end;  //retrieve all subsequent entries
      repeat
        dwEntrySize := 0;
        FindNextUrlCacheEntry(hCacheDir, TInternetCacheEntryInfo(nil^), dwEntrySize);
        dwLastError := GetLastError();    if dwLastError = ERROR_INSUFFICIENT_BUFFER then begin
          GetMem(lpEntryInfo, dwEntrySize);
          try
            if FindNextUrlCacheEntry(hCacheDir, lpEntryInfo^, dwEntrySize) then begin
              if ((lpEntryInfo^.CacheEntryType and NORMAL_CACHE_ENTRY) = NORMAL_CACHE_ENTRY) then
              begin
                if ((lpEntryInfo^.CacheEntryType and COOKIE_CACHE_ENTRY) = 0) or RemCookies then
                begin
                  if FileExists(string(lpEntryInfo^.lpszLocalFileName)) then
                    DeleteFile(string(lpEntryInfo^.lpszLocalFileName)); //delete file              DeleteUrlCacheEntry(lpEntryInfo^.lpszSourceUrlName);
                end;
              end;
            end else
              exit;
          finally
            FreeMem(lpEntryInfo);
          end;
        end else
          exit;
      until dwLastError = ERROR_NO_MORE_ITEMS;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      Screen.Cursor := crHourGlass;
      try
        ClearTempInternetFiles(true);
      finally
        Screen.Cursor := crDefault;
      end;
    end;end.