THttpCli.OnDocData

From Overbyte
Revision as of 17:43, 19 February 2006 by Wilfried (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Main page -> ICS components reference -> THttpCli -> OnDocData

Definition

procedure THttpCli.OnDocData(Sender: TObject; Buffer: Pointer; Len: Integer) of object;

  • Sender : the client which fired the event
  • Buffer : a pointer to the received data buffer
  • Len : number of bytes in the buffer

Description

This event will fire each time a buffer has been received from the server. You can use this method for example to find out how much data you received during the session. In HttpProt.pas the receive buffer size is set to 8193, which means for every chunk of 8193 bytes received from the server your event handler will be called.

Examples

see best practices

Best practices

If you update user interface elements (eg. progress bar) in this events it can create a huge overhead and slow down data transfer. If it is necesary to make UI updates in the event handler then you should do it only temporized updates. An example would be:

procedure TYourClass.HttpCliDocData(Sender: TObject; Buffer: Pointer; Len: Integer);
begin
   FReceivedLen := FReceivedLen + Len;

   {this is only a float comparison so it don't take too much time}
   if MilliSecondsBetween(Now, FLastReceivedTime) > 50 then begin
       FLastReceivedTime := Now;
       {Update UI only here in order to avoid slow tranfer rates}
   end;

   {if you are implementing limitation on max transfer size you can also do it here}
   if (FDataLen > DataLimit) then
       HttpClient.AbortRequest;
end;