TBitsOpenBit (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

The purpose of this example is to demonstrate the OpenBit, Size and Bits methods from the TBits class of the Classes unit. This example will test some bits in an array to see if their property is set to True or False.

Code

var
  Bits: TBits;
  I: Byte;

begin
  { Create a a bit set. }
  Bits := TBits.Create;
  
  { Set the size of the bit set. }
  Bits.Size := 10;
  
  { Set the even bits. }
  for I := 0 to Bits.Size - 1 do
    if not Odd(I) then
      Bits.Bits[I] := True else
      Bits.Bits[I] := False;
      
  { Display to the console which bit is set and which is not. }
  for I := 0 to Bits.Size - 1 do
    if Bits.Bits[I] = True then
      Writeln('Bit ', I, ' is set.') else
      Writeln('Bit ', I, ' is not set.');
      
  { Display the index of the first non-set bit. }
  Writeln('The index of the first non-set bit is ', Bits.OpenBit);
  
  { Free TBits }
  Bits.Free;
end.

Uses