Difference between revisions of "THttpCli.OnDocData"

From Overbyte
Jump to navigation Jump to search
 
Line 1: Line 1:
 
== Definition ==
 
== Definition ==
procedure (Sender: TObject; Buffer: Pointer; Len: Integer) of object;
+
procedure ('''Sender''': TObject; '''Buffer''': Pointer; '''Len''': Integer) of object;
  
* Sender : the client which fired the event
+
* '''Sender''' : the client which fired the event
* Buffer : a pointer to the received data buffer
+
* '''Buffer''' : a pointer to the received data buffer
* Len : number of bytes in the buffer
+
* '''Len''' : number of bytes in the buffer
  
 
== Description ==
 
== Description ==

Revision as of 11:24, 13 February 2006

Definition

procedure (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.

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.OnData(Sender: TObject; Buffer: Pointer; Len: Integer);
begin
 ReceivedLen := ReceivedLen + 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 (DataLen > DataLimit)and LimitFileSize then
   begin
     State := RS_IGNORE;
     HttpClient.AbortRequest;
   end;
end;