http OnDone event
Return to Introduction  Previous page  Next page
Applies to
WinHTTP component.  

Declaration
type  
  TWinHTTPDoneEvent = procedure(Sender: TObject;  
    const ContentType: String;  
    FileSize: Integer; Stream: TStream) of object;  
 
property OnDone: TWinHTTPDoneEvent;  

Description
The OnDone event occurs when the WinHTTP component has successfully downloaded requested data from the Web.  
 
The component pass to the OnDone event handler 3 following parameters:  
ParametersMeaning  
ContentTypethe media type (also known as Multipurpose Internet Mail Extension (MIME) type) of downloaded data. For example if you downloaded usual text-file, the ContentType will be "text/plan". For HTML page ContentType will "text/html", for executable file — "application/binary" and "image/jpeg" for JPEG, JPG and JPE files.  
For more information about Internet media types, please read RFC 2045, 2046, 2047, 2048, and 2077 (http://www.oac.uci.edu/indiv/ehood/MIME/MIME.html). Check out also the Internet media type registry at ftp://ftp.iana.org/in-notes/iana/assignments/media-types;  
FileSizesize of downloaded data in bytes;  
Streamthe memory stream which contains downloaded data (check out description of TMemoryStream class for more info). It can be nil (null) if the OutputFileName property was specified before request (before calling the Read method).  

Example
Delphi:
procedure TForm1.WinHTTP1Done(Sender: TObject;  
  ContentType: string; FileSize: Integer; Stream: TStream);  
var  
  Str: String;  
begin  
  if Stream = nil then   
    Exit; // can be already stored to file specified by OutputFileName  
 
  with Stream as TMemoryStream do  
   if OutToMemoBox1.Checked then // output to Memo1  
    begin  
     SetLength(Str, Size);  
     Stream.Read(Str[1], Size); // or Move(Memory^, Str[1], Size);  
     Memo1.Text := Str;  
    end  
   else  
    begin // save to file  
     Memo1.Text := 'Saved to c:\httptest.dat';  
     SaveToFile('c:\httptest.dat');  
    end;  
       
  StatusBar1.Panels[0].Text := 'Successfully downloaded ' + IntToStr(FileSize) + ' bytes';  
end;  



C++ Builder:

void __fastcall TForm1::WinHTTP1Done(TObject *Sender,  
      AnsiString ContentType, int FileSize, TStream *Stream)  
{  
  AnsiString Str;  
 
  if (Out1->Checked) {  
    Str.SetLength(Stream->Size);  
    Move(((TMemoryStream*)Stream)->Memory, &Str[1], Stream->Size);  
    Memo1->Text = Str;  
  }else {  
    Memo1->Text = "Saved to c:\httptest.dat";  
    ((TMemoryStream*)Stream)->SaveToFile("c:\httptest.dat");  
  }  
 
  StatusBar1->Panels->Items[0]->Text = "Successfully downloaded " + IntToStr(FileSize) + " bytes";  
}  

See also
OnProgress and OnHTTPError events; Read method;  
OutputFileName and FileName properties.