Difference between revisions of "THttpCli.OnDocData"
Jump to navigation
Jump to search
m (THttpCli:OnDocData moved to THttpCli.OnDocData) |
|||
Line 10: | Line 10: | ||
== Examples == | == Examples == | ||
− | ''see [ | + | |
+ | ''see [[THttpCli.OnDocData#Best_practices | best practices]]'' | ||
== Best practices == | == Best practices == |
Revision as of 11:02, 19 February 2006
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;