The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....


Declaration: [1] procedure InsertIntoArray (ArrayAdr: pointer; LengArray: longint; TypArray: TVarKind; value: pointer; index: longint);
[2] procedure InsertIntoArray (SArray: array of integer; value: integer; index: longint);
[3] procedure InsertIntoArray (SArray: array of single; value: single; index: longint);
[4] procedure InsertIntoArray (SArray: array of double; value: double; index: longint); {Pascal}
[2] void __fastcall InsertIntoArray(double * SArray, const int SArray_Size, double value, int index);
[3] void __fastcall InsertIntoArray(float * SArray, const int SArray_Size, float value, int index);
[4] void __fastcall InsertIntoArray(int * SArray, const int SArray_Size, int value, int index); {C++}

The routine InsertIntoArray supports the insertion of a new element into a linear array. This routine requires the address, the type, and the value of the new element, the length of the array, and the position where the new element should be inserted. InsertIntoArray shifts all elements from the position index one item back and stores the new element in the freed position. The last element of an array will be lost during this action.

The parameter ArrayAdr holds a pointer to the array (use the operator @). The parameter LengArray defines the length of this array (i.e. the maximum number of elements of this array). The parameter LengArray may be defined smaller than the actual size of the array. In this case only the first LengArray elements are processed by InsertIntoArray.

The parameter TypArray defines the type of the array elements. The users should be aware that a wrong designation of the type of the array elements leads to severe errors and can cause a system crash. The following types are valid: inum (integer), lnum (longint), snum (single), dnum (double), and rnum (real); the types strg (string) and bool (boolean) are not supported.

As an alternative to version [1] you may use the simpler versions [2], [3], and [4] for integer, single, or double precision arrays, respectively. Version [1] is only available for the Win32 environment, but not for .NET. The parameter SArray is an open array of integer, single, or double precision values.

In version [1] of InsertIntoArray the pointer value holds the address of the variable whose value should be inserted. This variable has to be of the same type as the elements of the array. For the other versions value contains the value to be inserted.

The parameter index specifies the position where to insert the value. If index is larger than LengArray (or High(SArray) in the case of versions [2]..[4]) the new value is not inserted at all. Please note that the array is assumed to be indexed from 1 to LengArray in version [1], and from 0 to High(SArray) for versions [2]..[4]. Thus the parameter index may assume values between 1 and LengArray for version [1], and values between 0 and High(SArray) for the other versions.

Hint 1: The procedure InsertIntoArray can be used to index a sorted array (see example program SORTINTO.PAS).

Hint 2: The declaration of the versions [2]..[4] of InsertIntoArray in C++ slightly differs from the Pascal declaration (note the extra parameter SArray_Size which specifies the highest index of the SArray array).

Hint 3: Due to a compiler bug, overloading with variable dynamic arrays does not function correctly under Delphi 5. In order to cope with this situation, the four overloaded versions have been assigned individual names under Delphi 5: [1] = InsertIntoArray, [2] = InsertIntoArrayInteger, [3] = InsertIntoArraySingle, [4] = InsertIntoArrayDouble.


The statement InsertIntoArray (@rfeld, 100, rnum, @newval, 12); inserts the real number newval into the array rfeld on position 12.

Last Update: 2012-Oct-20