Dynamic Arrays

Dynamic arrays are a very specific feature of Team Developer. They are similar to System.Collections.ArrayList, but can be multidimensional, and can be expanded also by accessing items out of sequence.

Using a native ArrayList you'd get an exception if the indexed element has not been added to the collection.

In the PPJ Framework we have implemented all dynamic array functionality into the PPJ.Runtime.SalArray class and have it specialized for each basic type in form of an inner class named Array for .NET 1.1 and using generics in .NET 2.0. In fact, the inner class technique used for .NET 1.1 is a form of generics coding.

String: strArray[*]

Is translated to:

SalString.Array strArray = new SalString.Array(); // .NET 1.1
SalArray<SalString> strArray = new  SalArray<SalString>(); // .NET 2.0 and above

SAL arrays can also specify multiple dimensions and/or the base index in the initializer.

Arrays declared using base initializers are ported using the overloaded string constructors in order to support the syntax with the colon:

String: strArray[2:10]

Is translated to:

// .NET 1.1
SalString.Array strArray = new SalString.Array("2:10");

// .NET 2.0 and above
SalArray<SalString> strArray = new  SalArray<SalString>("2:10");

Array Elements by Reference

Since the SalArray class uses the indexer property to access array elements, it is not possible to pass array elements by reference.

Additionally, because of the dynamic nature of SAL arrays, in Team Developer it's also possible to pass by reference an array element that does not exist, causing the array to be extended in line.

The implementation of SalArray in the PPJ Framework exposes the GetArray() function that returns the inner native array, therefore making it possible to pass elements by reference.

The GetArray() function accepts indices as arguments to make sure that the element to be passed by reference is created in the inner array.

For example:

Call SalGetItemName(hWndItem, strArray[10])

Is translated to:

Sal.GetItemName(Sys.hWndItem, ref strArray.GetArray(10)[10]);

The expression above means that the PPJ Framework first makes sure that there are at least 10 elements in the array, the returns the inner native array, and the tenth [10] element is then passed by reference to the function.

Last updated