SmartPascal
TBits
Type
An object that can hold an infinite number of Boolean values Classes unit
  type TBits;
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
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
 
unit Unit1;
 
interface
 
uses
  Classes,   // Unit containing the TBits command
  Forms, Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;
 
var
  
Form1: TForm1;
 
implementation
{$R *.dfm} // Include form definitions
 
procedure TForm1.FormCreate(Sender: TObject);

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;
 
end.
Hide 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