OPL development pages - Array.opx

OPX for dynamic string arrays (freeware)

What is Array.opx?
Array.opx is an OPL extension library that lets you use dynamic length string arrays in OPL. Features include adding, inserting and deleting items, finding and sorting.
Array.opx is available for the entire Nokia Communicator range (9210, 9210i, 9300, 9500).

Download Array.opx
You can download Array.opx from the Downloads page.

Usage
To use ARRAY.OPX, use the following statement at the beginning of your OPL application:

INCLUDE "ARRAY.OXH"

NOTE:
ARRAY.OPX functions can cause an OPL runtime error (for example when there is no more memory to add items). Since ARRAY.OPX allocates memory for the items stored in the array, you have to make sure that the memory allocated by the OPX is freed correctly if an error occurs. Failing to correctly release the memory allocated by the Array.opx will cause OPL to crash with an ALLOC error. , The following OPL-example demonstrates how to do this:

PROC TestArray:
LOCAL id&

  id&=ArrayNew&:
  ONERR FreeArray::

  REM Do some stuff with the created array
FreeArray::
  REM Make sure the array is freed
  ArrayFree(id&)
ENDP

All the functions in Array.opx that take an index parameter or return in an index into the array, come in two flavors; one that returns the index as an integer value and one that returns an index as a long integer value.

The functions that return a long integer always end with an 'L', for example the function ArrayAddItem%: adds an item to the array and returns the index of the position that the entry was added as an integer. ArrayAddItemL&: does exactly the same, but returns the index as a long integer. If the number of items in your array never exceeds the maximum number of integers (32765), it is more memory efficient to use the integer version of the array functions.

Installing ARRAY.OPX
To install Array.opx, double click on the ARRAYOPX.SIS-file in Windows Explorer or copy it to your device and open it from the FileManager application. After this, copy the Array.oxh file to the \SYSTEM\OPL folder on either drive C: or drive D:

Bugs or improvements
If you find any bugs or have further ideas for improvement, please let me know by sending an email to Arjen Broeze or by posting a message in the OPX and OPM support forum.

Documentation of ARRAY.OPX functions

ARRAY.OXH
REM Array.oxh
REM
REM Copyright (c) 2005 Arjen Broeze. All rights reserved.
REM

CONST KUidOpxArray&=&10204D05
CONST KOpxArrayVersion%=$120

REM Compare flags
CONST KArCmpNormal%=1
CONST KArCmpFolded%=2
CONST KArCmpCollated%=3

REM Sort flags
CONST KArSortAsc%=1 REM Sort Ascending
CONST KArSortDes%=2 REM Sort Descending

REM Duplicates flags
CONST KArDupAllow%=1 REM Allow duplicates
CONST KArDupIgnore%=2 REM Ignore duplicates
CONST KArDupError%=3 REM Duplicates will raise error KErrAlreadyExists%

REM Search type
CONST KArSearchSubstring%=1 REM Searches for substring
CONST KArSearchWildcard%=2 REM Searches for wildcard match

DECLARE OPX Array,KUidOpxArray&,KOpxArrayVersion%
    ArrayNew&: :1
    ArrayFree:(arrayId&) :2
    ArrayClear:(arrayId&) :3

    ArraySetDuplicates:(arrayId&,duplicates%) :4
    ArrayGetDuplicates%:(arrayId&) :5
    ArraySetCompareType:(arrayId&,compare%) :6
    ArrayGetCompareType%:(arrayId&) :7
    ArraySetSortMode:(arrayId&,sort%) :8
    ArrayGetSortMode%:(arrayId&) :9
    ArraySetSorted:(arrayId&,sorted%) :10
    ArrayGetSorted:(arrayId&) :11

    ArrayAddItem%:(arrayId&,value$) :12
    ArrayInsertItem:(arrayId&,index%,value$) :13
    ArrayReplaceItem:(arrayId&,index%,value$) :14
    ArrayDeleteItem:(arrayId&,index%) :15

    ArrayItemCount%:(arrayId&) :16

    ArrayItemAt$:(arrayId&,index%) :17
    ArrayFind%:(arrayId&,value$) :18

    ArraySort:(arrayId&) :19
    ArraySearch%:(arrayId&,startpos%,value$,searchType%) :20

    ArrayAddItemL&:(arrayId&,value$) :21
    ArrayInsertItemL:(arrayId&,index&,value$) :22
    ArrayReplaceItemL:(arrayId&,index&,value$) :23
    ArrayDeleteItemL:(arrayId&,index&) :24

    ArrayItemCountL&:(arrayId&) :25

    ArrayItemAtL$:(arrayId&,index&) :26
    ArrayFindL&:(arrayId&,value$) :27
    ArraySearchL&:(arrayId&,startpos&,value$,searchType%) :28
END DECLARE