FilledStructureArray - Create an array of structures and assign initial values

Top  Previous  Next

Syntax

 

<aStructures> := FilledStructureArray( <oStructureClass>, [<aMemberVarList>], <aFillData>  )

 

Parameters

 

<oStructureClass>

 

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

 

<aMemberVarList>

 

List of member variable names to be filled from <aFillData>. Default is "all member variables".

 

<aFillData>

 

Data used to fill the member variables of the created structures.

 

Return value

 

A one-dimensional array of structures of class <oStructureClasss> filled from <aFillData>. If an no data is passed <aFillData>, an empty array ( {} ) is returned. The size of the returned array depends on <aFillData>.

 

Description

 

FilledStructureArray creates a 1-dimensional array (=list) of structures. The member variables specified in <aMemberVarList> of these structures are filled with the data passed in <aFillData>. If no member variables are specified, FilledStructureArray will assume all member variables to be filled.

 

If <aFillData> is a 1-dimensional array, FilledStructureArray starts with a list containing one structure as return value. Every value in <aFillData> is assigned top-to-bottom to its member variables specified in <aMemberVarList>. If all specified member variables of this structure have been assigned and there are still elements in <aFillData> left, the next structure is added to the return value. Then FilledStructureArray starts filling the new  structurewith the remaining values. When the last value of <aFillData> has been assigned, FilledStructureArray finally returns. - In other words: FilledStructureArray creates as many  structuresas necessary to process all values in <aFillArray>.

 

If <aFillData> is a 2-dimensional array, FilledStructureArray creates a 1-dimensional array (=list) of <oStructureClass> structures as return value. The size if this array is determined by the first dimension of <aFillData>. Then the member variables of all structures in the return value array are assigned with the values of the sub arrays in <aFillData>. The member variables to be assigned with the values in the sub arrays can be specified with <aMemberVarList>. If <aMemberVarList> is not specified, the member variables are assigned top-to-bottom with the values from the sub arrays in <aFillData>. - In other words: FilledStructureArray creates a structure for every element in <aFillData> and assigns its member variables with the values specified of each sub array.

 

Classification

 

Core

 

Category

 

Structure

 

Quick Info

 

Library: cckptcor.lib / cckptcor.dll

 

See also

 

StructureArray, StructureArrayFrom

 

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 data,struArray

 

* Prepare some data in an array

data := { { 1 , 2 },;

         { 3 , 4 },;

         { 5 , 6 } }

 

* Create the array (3 elements)

struArray := FilledStructureArray(TESTSTRUCTURE(),,data)

 

* Check the size of the array

? Len(struArray)

 

* Display the contents of all structures in the list

? "Completely filled:"

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

 

* Now let's fill only word1 with values

struArray := FilledStructureArray(TESTSTRUCTURE(),{"word1"},{1,2,3})

 

* Display the contents of all structures in the list

? "Partially filled:"

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

 

* Fill top to bottom

struArray := FilledStructureArray(TESTSTRUCTURE(),,{1,2,3})

 

* Another diplay job

? "Filled with auto-assignment:"

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

 

RETURN NIL