Array.Compare

Top  Previous  Next

 

Syntax

function Array.Compare(Array1: array; Array2: array [; var DiffIndex: integer): integer

 

Alternative Names

ibec_CmpRecord
ibec_CmpRecord2

 

Description

Compares arrays Array1 and Array2 against each other. The following return values are possible:

 

-1

length of Array1 is smaller than length of Array2

0

arrays are equal

1

length of Array1 is larger than length of Array2

2

arrays have the same length, but different values

 

If the return value is 2, the optional DiffIndex parameter contains the array index with the first different value.

 

Example

execute UDSBlock returns (length_value integer, single_array_value varchar(100))

as

begin
  /* create two arrays with 6 elements */

  a1 = Array.Create(1, 'two', 3, 'four', 5, 'six');

  a2 = Array.Create(1, 'two', 3, 'four', 5, 'six');

  

  /* returns 0 */

  cmpresult = Array.Compare(a1, a2);

 

  a1[3] = 1;

  /* returns 2, diffindex 3 */

  cmpresult = Array.Compare(a1, a2, diffindex);

 

  /* make array1 smaller */

  Array.SetLength(a1, 4);

  /* returns -1 */

  cmpresult = Array.Compare(a1, a2);

end