Home  |  Delphi .net Home  |  System.Buffer  |  BlockCopy Method
  
BlockCopy  
Method  
Copies a block of bytes from one primitive array to another
Buffer Class
System NameSpace
CF1.  Procedure BlockCopy ( SourceBuffer : Array of PrimitiveType; SourceIndex : Integer; TargetBuffer : Array of PrimitiveType; TargetIndex : Integer; Count : Integer ) ; Static;
CF : Methods with this mark are Compact Framework Compatible
Description
Copies Count bytes from the index SourceIndex in SourceBuffer to TargetIndex in TargetBuffer.
 
It does not matter what the primitive data types are in each array - the Buffer class treats each as a block of bytes.
Notes
Static methods are not methods of an object - they are simply class functions or procedures available at any time.
Microsoft MSDN Links
System
System.Buffer
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
Copying from a Byte Array to an Int16 Array
program Project1;
{$APPTYPE CONSOLE}

var
  byteBuffer : Array of Byte;
  intBuffer  : Array of Int16;

  i       : Integer;

begin
  // Set the byte array to contain the number 17f (binary 10101010, hex AF)
  SetLength(byteBuffer, 10);
  for i := 0 to Length(byteBuffer)-1 do
    byteBuffer[i] := 175;

  // Display the byte array contents
  for i := 0 to Length(byteBuffer)-1 do
    Console.WriteLine('byteBuffer byte {0} = {1:X}',
                      i.ToString, TObject(byteBuffer[i]));

  // Set the Int16 array length to be 5 (Int16 types take 2 bytes)
  // And fill with zeros
  SetLength(intBuffer, 5);
  for i := 0 to Length(intBuffer)-1 do
    intBuffer[i] := 0;

  // Copy 4 bytes from the byte array to index 3 of the Int16 array
  System.Buffer.BlockCopy(byteBuffer, 0, intBuffer, 3, 4);

  // And display the Int16 array contents
  Console.WriteLine;
  for i := 0 to Length(intBuffer)-1 do
    Console.WriteLine('intBuffer Integer {0} = {1:X}',
                      i.ToString, TObject(intBuffer[i]));

  Console.ReadLine;
end.
   byteBuffer byte 0 = AF
   byteBuffer byte 1 = AF
   byteBuffer byte 2 = AF
   byteBuffer byte 3 = AF
   byteBuffer byte 4 = AF
   byteBuffer byte 5 = AF
   byteBuffer byte 6 = AF
   byteBuffer byte 7 = AF
   byteBuffer byte 8 = AF
   byteBuffer byte 9 = AF
  
   intBuffer Integer 0 = 0
   intBuffer Integer 1 = AF00
   intBuffer Integer 2 = AFAF
   intBuffer Integer 3 = AF
   intBuffer Integer 4 = 0
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author