Home  |  Delphi .net Home  |  System.Array  |  GetValue Method
  
GetValue  
Method  
Gets the value from an element of the current array
Array Class
System NameSpace
CF1.  Function GetValue ( Index : Integer ) : Object;
NotCF2.  Function GetValue ( Index0 : Integer; Index1 : Integer ) : Object;
NotCF3.  Function GetValue ( Index0 : Integer; Index1 : Integer; Index2 : Integer ) : Object;
NotCF4.  Function GetValue ( Index : Int64 ) : Object;
NotCF5.  Function GetValue ( Index0 : Int64; Index1 : Int64 ) : Object;
NotCF6.  Function GetValue ( Index0 : Int64; Index1 : Int64; Index2 : Int64 ) : Object;
CF7.  Function GetValue ( Indices : Array of Integer ) : Object;
NotCF8.  Function GetValue ( Indices : Array of Int64 ) : Object;
CF : Methods with this mark are Compact Framework Compatible
Description
Returns the value at the specified array position.
 
For a single dimensional array, Index provides the position.
 
For multidimentional arrays, Index0, Index1, Index2 or Indices specify the dimension positions
Microsoft MSDN Links
System
System.Array
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
Getting values from a single dimension array
program Project1;
{$APPTYPE CONSOLE}

var
  myArray : System.Array;
  i       : Integer;

begin
  // Create a 4 element single dimension array of strings
  myArray := System.Array.CreateInstance(TypeOf(String), 4);

  // Fill the array with values
  myArray.SetValue('Hello',  0);
  myArray.SetValue('from',   1);
  myArray.SetValue('Delphi', 2);
  myArray.SetValue('Basics', 3);

  // Display the array contents
  for i := 0 to myArray.Length-1 do  // Arrays are always 0 based
    Console.WriteLine('myArray[{0}] = {1}',
                       i.ToString, myArray.GetValue(i));

  Console.ReadLine;
end.
   myArray[0] = Hello
   myArray[1] = from
   myArray[2] = Delphi
   myArray[3] = Basics
Getting values from a multidimensional array
program Project1;
{$APPTYPE CONSOLE}

var
  myArray : System.Array;       // .Net array
  lengths : Array of Integer;   // Native Delphi dynamic array
  value   : Integer;
  i0, i1  : Integer;

begin
  // First, we define the array that holds the lengths of each
  // dimension of our multi-dimensional array
  SetLength(lengths, 2);  // Dynamic arrays are always 0 based

  lengths[0] := 2;
  lengths[1] := 3;

  // Create a multi dimensional array of integers
  myArray := System.Array.CreateInstance(TypeOf(Integer), lengths);

  // Fill the array with values
  for i0 := 0 to myArray.GetUpperBound(0) do
    for i1 := 0 to myArray.GetUpperBound(1) do
      begin
        // Create an element value according to its array position
        value := i0 + i1;
        myArray.SetValue(TObject(value), i0, i1);
      end;

  // Display the array contents
  for i0 := 0 to myArray.GetUpperBound(0) do
    for i1 := 0 to myArray.GetUpperBound(1) do
      begin
        // Get the array element value
        value := Integer(myArray.GetValue(i0, i1));
        Console.WriteLine('myArray[ ' + i0.ToString + ', '   +
                                        i1.ToString + '] = ' +
                                        value.ToString);
      end;

  Console.ReadLine;
end.
   myArray[ 0, 0] = 0
   myArray[ 0, 1] = 1
   myArray[ 0, 2] = 2
   myArray[ 1, 0] = 1
   myArray[ 1, 1] = 2
   myArray[ 1, 2] = 3
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author