Indy 9
TIdManagedBuffer
Hierarchy, Properties, Methods, Unit: IdTCPConnection
Extended buffer class that allows access to the memory allocated to the buffer.
TIdManagedBuffer = class(TIdSimpleBuffer)
Unit
IdTCPConnection
Description
TIdManagedBuffer is a TIdSimpleBuffer descendant that extends the ancestor class to include properties and methods used for maintaining and accessing the memory used for the buffer. TIdManagedBuffer is the type used to represent the TIdTCPConnection.InputBuffer property.

TIdManagedBuffer.PackReadedSize
TIdManagedBuffer, See Also
Indicates the number of bytes needed for the internal buffer for the managed buffer instance.
property PackReadedSize: Integer;
Description
PackReadedSize is an Integer property that indicates the number of bytes to use for the internal buffer used to hold values read for the managed buffer. PackReadedSize also determines when PackBuffer is called in Remove.

Changing the value in PackReadedSize to a non-positive value causes IdInBufCacheSizeDefault to be assigned as the property value.

The default value for PackReadedSize is IdInBufCacheSizeDefault as assigned in the Create constructor.


TIdManagedBuffer.Clear
TIdManagedBuffer, See Also
Clears the memory allocated to the buffer.
procedure Clear;
Description
Clear is a procedure that allows the buffer class to clear the memory allocated to the buffer. Clear calls the inherited Clear method, and sets the number of bytes read to 0.

TIdManagedBuffer.Create
TIdManagedBuffer, See Also
Constructor for the object instance.
constructor Create(AOnBytesRemoved: TIdBufferBytesRemoved = nil);
Parameters
AOnBytesRemoved: TIdBufferBytesRemoved = nil
Event handler to call when removing contents from the buffer.
Description
Create is the constructor for the object instance. Create calls the inherited Create method using AOnBytesRemoved as the event handler used when removing bytes from the memory for the buffer. Create sets the default value of PackReadedSize to IdInBufCacheSizeDefault prior to exiting from the method.

TIdManagedBuffer.Extract
TIdManagedBuffer, See Also
Copies and removes bytes from the memory for the buffer.
function Extract(const AByteCount: Integer): string; override;
Parameters
const AByteCount: Integer
Number of bytes to be removed from the memory allocated to the buffer.
Description
Extract is a String function used to remove the number of byes indicated in AByteCount from the Memory allocated to the buffer. Extract can raise an EIdNotEnoughDataInBuffer instance when AByteCount exceeds the size of the allocated buffer. Extract copies the number of bytes specified to the Result value, and calls Remove using AByteCount as an argument.

TIdManagedBuffer.Memory
TIdManagedBuffer, See Also
Provides access to the unread storage allocated for the buffer.
function Memory: Pointer;
Description
Memory is a Pointer function that provides access to the unread storage allocated for the buffer. Memory is normally accessed by a dereferenced pointer to the PChar values for the buffer. Use Clear, Extract, or Remove to read or reset Memory contents.

TIdManagedBuffer.PackBuffer
TIdManagedBuffer, See Also
Removes read values and resizes the allocated memory for the buffer.
procedure PackBuffer;
Description
PackBuffer is a procedure used to clear values from Memory that had been read. PackBuffer uses ReadedSize to determine the number of bytes already read from the buffer. When ReadedSize is greater than zero (0), PackBuffer calls Move to make unread bytes appear at the beginning of Memory allocated for the buffer and resizes the memory stream to Size. PackBuffer sets the number of bytes read to zero (0) prior to exiting from the method.

TIdManagedBuffer.Remove
TIdManagedBuffer, See Also
Removes the spcified number of bytes from the internal cache.
procedure Remove(const AByteCount: integer); override;
Parameters
const AByteCount: integer
Number of bytes to remove from the managed buffer.
Description
Remove is a procedure used to increment the number of bytes read for the managed buffer by the value specified in AByteCount, and cause the bytes to be removed from the internal cache.

Remove can raise an EIdNotEnoughDataInBuffer exception when AByteCount is larger than Size of the internal cache for the managed buffer. When AByteCount is equal to Size, Remove calls the Clear method. Otherwise, Remvoe increments the ReadedSize property by the number of bytes specified in AByteCount.

If ReadedSize is larger than the threshold value indicated in PackReadedSize, Remove calls PackBuffer to adjust the internal cache size to reflect the unhandled contents of the managed buffer.

The OnBytesRemoved event handler is triggered (when assigned) using the specifed number of bytes in AByteCount.

Use Extract to retrieve and remove a specified number of bytes from the contents of a managed buffer.


TIdManagedBuffer.Seek
TIdManagedBuffer
Moves the current location in the managed buffer to the specified position.
function Seek(Offset: Longint; Origin: Word): Longint; override;
Parameters
Offset: Longint
Number of bytes to move from the specified origin.
Origin: Word
Buffer location to use as the intial seek position.
Description
Seek is a LongInt function used to moves the current location in the managed buffer to the position indicated by the Offset and Origin arguments. Seek allows the managed buffer to emulate the positioning used in a TStream object but on the Memory position for the managed buffer.

If Offset is from the beginning of the resource, Seek moves to the position Offset in Memory. Offset must be greater than 0. When Offset is from the current position in the resource, Seek moves to the current Position + Offset. When Offset is from the end of the resource, Offset must be less than or equal to 0 to indicate a number of bytes before the end of the buffer.

Seek returns the new Position in the Memory property, the new current position in the resource.


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