Delphi:TBitList
TBitList is very similar to the TBits class in Delphi. Like TBits, it can be used to efficiently store a virtually unlimited number of boolean values as a bitfield - i.e. consuming only one bit per boolean. When a very large number of boolean values need to be stored, this is considerably more economical than using an array of booleans. Unlike TBits, the underlying code is easier to modify. In addition, TBitList supports streaming - i.e. you can easily write your bitfield booleans to a stream and retrieve them later. TBitList has three key properties
- Position:Word - This readonly property indicates the index of the next bitbool to be read/written.
- Size: Word - This readonly property gives you the current size of the memory block used to store bitbool values.
- Bits[Index: Integer] :Boolean - The array of boolean values stored in TBitList. Using an invalid index value triggers a EBitList exception. This is the default property.
The principal methods of TBitList are listed below
- constructor CreateEx - This is the object constructor. Internally, it reserves sufficient memory to write 32 bitbools. The size of this memory block is automatically adjusted as you add new values.
- constructor CreateFromStream( AStream: TStream )- Use this constructor to recreate a TBitList instance from previously streamed data.
- procedure WriteToStream( AStream: TStream ) - As the name implies, this method is used to write bitbool data to a TStream descendant.
- procedure AddBit( Value: Boolean ) - Use this method to store a new bitbool value. The size of the memory block used to store bitbools will be automatically adjusted, if necessary.
- function FetchBit :Boolean - Returns the value of the next bitbool in a stored sequence. Typically you would use this method immediately after recreating a streamed TBitList instance starting from the first stored value, i.e.
FPosition = 0. - procedure ReSet - Empties the list and prepares it to accept new bitbool entries.
Usage: Create an instance of TBitList whenever you need to store a sequence of related integers. Use TBitList methods and properties to manage your entries. Remember to free the instance once you are done.
Download