StructureArray - Create an array of structures of the same class

Top  Previous  Next

Syntax

 

<aStructures> := StructureArray( <oStructureClass>, <nDim1> {,<nDim2..n> } )

 

Parameters

 

<oStructureClass>

 

Class object of the structure to be used for the array.

 

<nDim1..n>

 

List of dimensions of the array to be created. If nDim1 is passed as an array, it is used to define the extents of the created array. In this case the following parameters are not used.

 

Return value

 

An array of structures of class <oStructureClasss> with the dimensions <nDim1> to <nDimn>.

 

Description

 

StructureArray creates a symmetric array with the dimensions <nDim1> to <nDimn> and fills it with empty structures of class <oStructureClass>. Specifying only <nDim1> will create a list, specifying <nDim1> and <nDim2> will create a matrix of structures and so on.

 

Instead of passing a separate parameter for every dimension in the target array, an array containing the extents of all dimensions can be passed in <nDim1>.

 

Classification

 

Core

 

Category

 

Structure

 

Quick Info

 

Library: cckptcor.lib / cckptcor.dll

 

See also

 

StructureArrayFrom, FilledStructureArray

 

Example

 

 

#INCLUDE "CockpitCoreLibs.ch"

#INCLUDE "ExtendedStructures.ch"

 

* Set up a simple structure

MEMBERLIST TESTSTRUCTURE

MEMBER word1

MEMBER byte1

ENDMEMBERLIST

 

STRUCTURE TESTSTRUCTURE

WORD word1

BYTE byte1

ENDSTRUCTURE

 

 

FUNCTION Main

 

LOCAL struArray,m,n

 

* Create a 2 by 2 matrix

struArray := StructureArray(TESTSTRUCTURE(),2,2)

 

* Check the size

? Len(struArray)

? Len(struArray[1])

 

* Fill the structures with some values

FOR n := 1 TO Len(struArray)

   FOR m := 1 TO Len(struArray[n])

       struArray[n][m]:word1 := n

       struArray[n][m]:byte1 := m

   NEXT m

NEXT n

 

* Display the contents of all structures in the matrix

AEval(struArray,{|row|AEval(row,;

                     {|elem|QOUT(elem:word1,",",elem:byte1)})})

 

RETURN NIL