Description |
The TBits type holds a flexible collection of bits (Boolean values).
The colection size can be altered at any time (using the size property).
Bits are accessed using the Bits property, like this :
flag := myBits.Bits[2];
or, more simply:
flag := myBits[2];
There is one utility function - OpenBit - which returns the index of the first false value. There is no equivalent for true values.
|
|
Related commands |
Array |
|
A data type holding indexable collections of data |
Boolean |
|
Allows just True and False values |
|
|
|
Example code : A simple example |
var flags : TBits; // Our variable collection of Boolean values
i : Integer;
begin // Create our TBits object
flags := TBits.Create;
// Add a few items to our Boolean flags collection
flags.Size := 5;
// And set a few values
flags[0] := true;
flags[1] := true;
flags[4] := true;
// Now display the contents of the collection // Note that indexing starts at 0
for i := 0 to flags.Size-1 do
if flags[i] = true
then ShowMessageFmt('Bit %d is true',[i])
else ShowMessageFmt('Bit %d is false',[i]);
// TBits has one main method - // to find the index of the first false value
ShowMessageFmt('Index of the first false value is %d',[flags.OpenBit]);
end;
|
Show full unit code |
Bit 0 is true
Bit 1 is true
Bit 2 is false
Bit 3 is false
Bit 4 is true
Index of the first false value is 2
|
|