http OnDone event
Return to Introduction  Previous page  Next page
Applies to
acHTTP, acWebImage and acSQLQueryThread components.  

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

The OnDone event occurs when the acHTTP component has successfully downloaded requested Web resource.  
The component pass to the OnDone event handler 3 following parameters:  
ContentTypethe media type (also known as Multipurpose Internet Mail Extension (MIME) type) of requested document. 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 ( Check out also the Internet media type registry at;  
FileSizesize of downloaded data in bytes;  
Streamthe stream which contains downloaded data (this is actually TMemoryStream. Check out description of TMemoryStream class for more details on how to retreive data from it). iiwarning However, it can be nil (null) if the OutputFileName property was specified before request (before calling the Read method).  

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

C++ Builder:

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

See also
OnProgress, OnHTTPError, OnHeaderInfo and OnDoneInterrupted events;  
Read and Abort methods;  
OutputFileName, OutputFileAttributes and FileName properties.