Indy 9 | Content | Index | Reference

TIdSimpleBuffer
Hierarchy, Methods, See Also, Unit: IdTCPConnection
Buffer used in Indy read and write operations.

    TIdSimpleBuffer = class(TMemoryStream)

Unit
IdTCPConnection
Description
TIdSimpleBuffer is a TMemoryStream descendant used in buffered read and write operations for Indy components. TIdSimpleBuffer includes all the inherited stream functionality of TMemoryStream, and extends the class with the Extract and Remove methods to manage buffer usage in Indy.

TIdSimpleBuffer also provides a protected TIdBufferBytesRemoved event handler that allows notification of data removal from the buffer.

TIdSimpleBuffer is used as a generic buffer in operations that read data from the TCP/IP protocol stack, and in classes that perform read or write buffering like TIdTCPConnection.

TIdSimpleBuffer.Create
TIdSimpleBuffer, See Also, Example 1, Example 2
Constructor for the object instance.

    constructor Create(AOnBytesRemoved: TIdBufferBytesRemoved = nil); reintroduce;

Parameters
AOnBytesRemoved: TIdBufferBytesRemoved = nil
Procedure to assign to the protected event handler. Default is nil.
Description
Create is the constructor for the object instance, reintroduced in TIdSimpleBuffer to provide the event handler used for removal of data from the buffer. Create calls the inherited Create method, and assigns the TIdBufferBytesRemoved event handler in AOnBytesRemoved to the protected OnBytesRemoved event handler.

TIdSimpleBuffer.Extract
TIdSimpleBuffer, See Also
Reads and removes the specified number of bytes from the buffer.

    function Extract(const AByteCount: Integer): string; virtual;

Parameters
const AByteCount: Integer
Number of bytes to read and remove from the buffer.
Return Value
String - Values removed from Memory allocated to the buffer.
Description
Extract is a String function used to Read and remove the number of bytes specified in AByteCount from the buffer. Extract will raise an EIdNotEnoughDataInBuffer exception if the buffer Size is smaller than the number of bytes indicated in AByteCount.

Extract sets the return value for the method to the contents indicated in Memory starting at the current Position, and including up to AByteCount chatacters. Extract calls Remove to delete AByteCount characters from the buffer on successful completion of the method.

TIdSimpleBuffer.Remove
TIdSimpleBuffer, See Also
Removes bytes of data from the memory buffer.

    procedure Remove(const AByteCount: integer); virtual;

Parameters
const AByteCount: integer
Number of bytes to be removed.
Description
Remove is a procedure used to to remove the number of bytes in AByteCount from the memory buffer. Remove shifts the contents of Memory so that only data bytes AByteCount through the Size of the buffer are available for further processing. When ByteCount and Size are the same, the memory buffer in Memory is reset using Clear.

Remove will raise an EIdNotEnoughDataInBuffer exception when AByteCount is larger than the Size of Memory in TIdBuffer.

Removes triggers the protected OnBytesRemoved event handler, when assigned, after data has been removed from the Memory in TIdSimpleBuffer.

Note: Data in Memory should be handled in the manner appropriate to the application prior to calling Remove.

Created with Doc-O-Matic 2 donated to Project JEDI. Commercial license available from the Doc-O-Matic site.