Autor Beitrag
NOS1971
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 193

Windows 8.1 PRO 64 Bit
Delphi XE7 Professional
BeitragVerfasst: Mi 24.04.13 22:46 
Hi,

ich nutze diese Funktion um mir eine Datei aus dem Web in einen Stream zu lesen und durch den Inhalt der Datei festzustellen ob es ein update der software gibt. Obwohl ich die Datei in einen Stream lade scheint er diese aus dem Cache und nicht wie festgelegt aus dem Web zu laden. Wie kann ich es verhindern das die Datei aus dem Cache geladen wird ? weil ich das auch als grundroutine für einige webseitenanalysefunktionen nutze wäre es generell sinnig das der cache nicht genutzt wird. Ich hoffe Ihr könnt helfen.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
function UrlDownloadToStream(URL: String; Stream: TStream): Boolean;
var  ppStream:   IStream;
     statstg:    TStatStg;
     lpBuffer:   Pointer;
     dwRead:     Integer;
begin
  // Set default result
  result:=False;

  // Make sure stream is assigned
  if Assigned(Stream) then
  begin
     // Open blocking stream
     if (URLOpenBlockingStream(nil, PChar(URL), IStream(ppStream), 0nil) = S_OK) then
     begin
        // Resource protection
        try
           // Get the stat from the IStream interface
           if (ppStream.Stat(statstg, STATFLAG_NONAME) = S_OK) then
           begin
              // Make sure size is greater than zero
              if (statstg.cbSize > 0then
              begin
                 // Allocate buffer for the read
                 lpBuffer:=AllocMem(statstg.cbSize);
                 // Resource protection
                 try
                    // Read from the stream
                    if (ppStream.Read(lpBuffer, statstg.cbSize, @dwRead) = S_OK) then
                    begin
                       // Write to delphi stream
                       Stream.Write(lpBuffer^, dwRead);
                       // Resource protection
                       try
                          // Rewind
                          Stream.Seek(-dwRead, soFromCurrent);
                       finally
                          // Success
                          result:=True;
                       end;
                    end;
                 finally
                    // Free the buffer
                    FreeMem(lpBuffer);
                 end;
              end;
           end;
        finally
           // Release the IStream interface
           ppStream:=nil;
        end;
     end;
  end;
end;