Skip to content

SortInt ​

The SortInt procedure sorts the array of integer values aValues, into ascending numeric order.

This function only works with integers - not floating-point numbers.

To sort an array with links to another array, please review the procedure SortIntEx.

Declaration: Procedure SortInt(var aValues : TIntegerArray);

Example with a wide range of integer values.

pascal
procedure ScriptEvent (var Value : variant);
var
  arrSort : TIntegerArray;
  i : Integer;
begin

  SetLength(arrSort, 11);
  arrSort[0] := 673;
  arrSort[1] := 2;
  arrSort[2] := 78;
  arrSort[3] := -34;
  arrSort[4] := 289;
  arrSort[5] := 945;
  arrSort[6] := 274;
  arrSort[7] := 4587;
  arrSort[8] := 47;
  arrSort[9] := 2189;
  arrSort[10] := -4588;

  LogInfo('');
  LogInfo('Array unsorted ----------------------');
 for i := Low(arrSort) to High(arrSort) do
 begin
    LogInfo(varToStr(i) + ': ' + varToStr(arrSort[i]));
 end;

  SortInt(arrSort);                         //Sort the array integer values

  LogInfo('');
  LogInfo('Array sorted ------------------------');
 for i := Low(arrSort) to High(arrSort) do
 begin
    LogInfo(varToStr(i) + ': ' + varToStr(arrSort[i]));
 end;
  LogInfo('');

end;