Difference between revisions of "THttpCli.OnDocData"

From Overbyte
Jump to navigation Jump to search
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
[[Main_Page | Main page]] -> [[ICS_Components_Reference | ICS components reference]]
 +
-> [[THttpCli]] -> [[THttpCli.OnDocData | OnDocData]]
 
== Definition ==
 
== Definition ==
procedure ('''Sender''': TObject; '''Buffer''': Pointer; '''Len''': Integer) of object;
+
procedure [[THttpCli]].OnDocData('''Sender''': TObject; '''Buffer''': Pointer; '''Len''': Integer) of object;
  
 
* '''Sender''' : the client which fired the event
 
* '''Sender''' : the client which fired the event
Line 10: Line 12:
  
 
== Examples ==
 
== Examples ==
''see [http://wiki.overbyte.be/wiki/index.php/THttpCli:OnDocData#Best_practices best practices]''
+
 
 +
''see [[THttpCli.OnDocData#Best_practices | best practices]]''
  
 
== 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:
 
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);
+
  procedure TYourClass.HttpCliDocData(Sender: TObject; Buffer: Pointer; Len: Integer);
 
  begin
 
  begin
  FReceivedLen := FReceivedLen + Len;
+
    FReceivedLen := FReceivedLen + Len;
 
   
 
   
  {this is only a float comparison so it don't take too much time}
+
    {this is only a float comparison so it don't take too much time}
  if MilliSecondsBetween(Now, FLastReceivedTime) > 50 then
+
    if MilliSecondsBetween(Now, FLastReceivedTime) > 50 then begin
    begin
+
        FLastReceivedTime := Now;
      FLastReceivedTime := Now;
+
        {Update UI only here in order to avoid slow tranfer rates}
      {Update UI only here in order to avoid slow tranfer rates}
 
 
     end;
 
     end;
 
   
 
   
  {if you are implementing limitation on max transfer size you can also do it here}
+
    {if you are implementing limitation on max transfer size you can also do it here}
  if (FDataLen > DataLimit)
+
    if (FDataLen > DataLimit) then
    then HttpClient.AbortRequest;
+
        HttpClient.AbortRequest;
 
  end;
 
  end;

Latest revision as of 17:43, 19 February 2006

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;