Home  |  Delphi .net Home  |  System.Collections.BitArray  |  Set Method
  
Set  
Method  
Sets a BitArray element value on (true) or off (false)
BitArray Class
System.Collections NameSpace
CF1.  Procedure Set ( Index : Integer; Value : Boolean ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
The bit at 0-based Index position in the current BitArray is set to Value.
Notes
IMPORTANT : at the time of writing, this function fails to operate in Delphi 8 .Net (initial Profesional version release). It generates the following error message :

Identifier expected but 'SET' found.

The exmple below currently produces this error message.
Microsoft MSDN Links
System.Collections
System.Collections.BitArray
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
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 bit 2 off and bit 3 on
  Bits.&Set(2, false);
  Bits.&Set(3, true);

  Console.WriteLine;
  Console.WriteLine('After setting bit 2 off, bit 3 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.
   Bits [0] = 0
   Bits [1] = 1
   Bits [2] = 1
   Bits [3] = 0
   Bits [4] = 0
  
   After setting bit 2 off, bit 3 on :
  
   Bits [0] = 0
   Bits [1] = 1
   Bits [2] = 0
   Bits [3] = 1
   Bits [4] = 0
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author