Home  |  Delphi .net Home  |  System.Collections.BitArray  |  SetAll Method
SetAll  
Method  
Sets all BitArray element values either on (true) or off (false)
BitArray Class
System.Collections NameSpace
CF1.  Procedure SetAll ( Value : Boolean; ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
All elements in the current BitArray are set to Value.
Microsoft MSDN Links
System.Collections
System.Collections.BitArray
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.Collections;

var
  Bits : System.Collections.BitArray;
  i    : Integer;

begin
  // Create our bit array
  Bits := System.Collections.BitArray.Create(5);

  // Set the values in both arrays
  Bits[0] := false;  // 0
  Bits[1] := true;   // 1
  Bits[2] := true;   // 1
  Bits[3] := false;   // 0
  Bits[4] := false;   // 0

  for i := 0 to Bits.Count-1 do
    if Bits[i]
    then Console.WriteLine('Bits [{0}] = 1', i.ToString)
    else Console.WriteLine('Bits [{0}] = 0', i.ToString);

  // Set all bits on
  Bits.SetAll(true);

  Console.WriteLine;
  Console.WriteLine('After setting all bits on :');
  Console.WriteLine;

  for i := 0 to Bits.Count-1 do
    if Bits[i]
    then Console.WriteLine('Bits [{0}] = 1', i.ToString)
    else Console.WriteLine('Bits [{0}] = 0', i.ToString);

  Console.ReadLine;
end.
Show full unit code
  Bits [0] = 0
  Bits [1] = 1
  Bits [2] = 1
  Bits [3] = 0
  Bits [4] = 0
  
  After setting all bits on :
  
  Bits [0] = 1
  Bits [1] = 1
  Bits [2] = 1
  Bits [3] = 1
  Bits [4] = 1
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author