TIdSimpleBuffer
Buffer used in Indy read and write operations.
TIdSimpleBuffer = class(TMemoryStream)
Unit
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.
Constructor for the object instance.
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.
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.
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.