Show/Hide Toolbars

XSharp

This type is used for typed arrays. It has been introduced in the X# Runtime. The internal typename is XSharp.__ArrayBase
The code below shows how you can use it.

Many of the existing XBase runtime functions that accept arrays now also accept an ARRAY OF.

Runtime functions that expect a codeblock for Arrays expect a Lambda expression for ARRAY OF.

The difference is that the parameters to the Lambda expression will be typed, so no late binding is necessary.

Parameters to a Codeblock are always of type usual and therefore either require Late Binding support or need to be casted to the right type inside the codeblock.

We have also introduced a special multidimensional syntax. Given the example below you can also get the first name of the first developer in the array by using the following syntax:

  cFirst := aDevelopers[1, "FirstName"]

 

This may be useful when you work with existing generated code and the existing code was using a define for the elements in the multidimensional array.

If you had a (generated) define like

DEFINE DEVELOPER_FirstName := 1

then you can change the code generator and generate this instead

DEFINE DEVELOPER_FirstName := "FirstName"

The code that uses the define can remain unchanged

  cFirst := aDevelopers[1, DEVELOPER_FirstName]

Example code

FUNCTION Start AS VOID                          
// declare typed array of developer objects  
LOCAL aDevelopers AS ARRAY OF Developer          
// Initialize the array with the "normal" array syntax
aDevelopers   := {}
// AAdd also supports typed arrays
AAdd(aDevelopers, Developer  { "Chris","Pyrgas"})
AAdd(aDevelopers, Developer  { "Nikos", "Kokkalis"})
AAdd(aDevelopers, Developer  { "Fabrice", "Foray"})
AAdd(aDevelopers, Developer  { "Robert", "van der Hulst"})    
// AEval knows that each element is a developer
AEval(aDevelopers, { d => Console.WriteLine(d)})
// ASort knows the type and passes the correct types to the lambda expression.
// The compiler and runtime "know" that x and y are Developer objects and will produce early bound code
ASort( aDevelopers, 1, ALen(aDevelopers), { x, y => x:LastName < y:LastName})  
// Foreach knows that each element is a Developer object
FOREACH VAR oDeveloper IN aDevelopers                                              
  ? oDeveloper:LastName, oDeveloper:FirstName
NEXT
RETURN
 
CLASS Developer
  PROPERTY FirstName AS STRING AUTO
  PROPERTY LastName AS STRING AUTO  
     CONSTRUCTOR()
        RETURN
  CONSTRUCTOR (cFirst AS STRING, cLast AS STRING)
       FirstName := cFirst
       LastName  := cLast
  METHOD ToString() AS STRING
      RETURN Firstname+" " + LastName
END CLASS