The Meta Instruction Set - Loops.

The loop type meta instructions do not create loops in the generated code. They cause the meta generator to loop around all the objects appropriate to the loop used. Each sets the CMSO to a different object type. They also all set the variable CMSO.

Basic loops.

The following loops can be used as the first level, or they can be nested inside each other. When they are the first level, you need to add a parameter to indicate the starting point for the meta generator.

Loop instruction CMSO type Parameter Comment
+For Each Variable Variable Variable group property Cannot be nested, parameter always required.
+For Each View View Variable  
+For Each Field Field Variable Can be used inside a View or Variable loop.
+For Each Non-View Field Field Variable  

 The last of these loops will find all the fields in a variable that are not there through a view.

Once you have established the field CMSO the following two loops can be used to interrogate the properties of the current field.

Loop instruction CMSO type
+For Each Field Component Field
+For Each Field Value Value

The first of these will expand any structured or multiple occurrence (array) field into the lowest level components. Each of these can then be processed inside the loop. Only the lowest level, or atomic, elements are available. Any intermediate structures are ignored.
For example:

only the fields underlined in red will be processed inside the +For Each Field Component loop.

 These simple loops are used in the class libraries for field level validation. This piece of code shows the loops in the the business entity.Standard functions.Create user interface and Field validation functions.

The first loop establishes both the view and variable CMSOs. In this case the variable CMSO is set to the Details variable. Inside this, the +For Each Field loop then process each field in turn. You should be familiar with some of the code inside this loop, the generated test and function call were explained in a previous part. The net result of this code is that any field on the Details region will have its validation function called, if one exists. If the called function returns an error, the appropriate field is set to the Error control state.

Data model loops.

There are three specialized loops, designed for nesting within a +For Each View loop. They are:

Loop instruction CMSO type
+For Each Entity Relation Triple
+For Each Field Relation Triple
+For Each Dependency Triple

 The first of these will set the triple CMSO to each ENT owned by ENT or ENT refers to ENT triple in turn. Since the triple CMSO is set, you can interrogate the model for continuation triples of these verbs, TRP ...optionality SYS for example.

The second loop is similar to the first except that it looks for the ENT known by FLD and ENT has FLD triples.

It is important to remember that these loops only set the triple CMSO. Setting the field CMSO for the fields that are part of the relation is done by a different loop, covered a little later.

The last of the three loops is somewhat odd in that it interrogates the model in Usage mode. In other words, it looks at the model with the CMSO as the target object of verbs, rather than the normal source of verbs. The triple CMSO is set for each triple where the entity scoping the view of the outer meta loop is the target. For example, if the data model contains these triples:

and you used a +For Each Dependency for the Alpha entity, the triple CMSO would be set to following triples:

Bravo owned by Alpha
Charlie owned by Alpha
Delta refers to Alpha

Multiple relations to the same entity are treated separately.

This loop is most useful for coding to maintain referential integrity and is used in the row deletion validation processing in the class libraries. Look at the class library Business entity.Real attribute.Delete valid instance function to see how the loop is used.

Relation attributes.

The loops in the previous section only set the triple CMSO. To be able to operate on the fields that constitute each relation, you need to use the +For each attribute loop. This expands the relation and finds all the fields on the view through the relation. In the case of the field type relations (Known by and Has verbs) there is only ever one field, the target object of the verb but for entity-to-entity relations, there may be many fields. These include the keys from the target entity, along with any virtual fields included on the relation. It can only be used inside one of the above loops.

The class libraries use this type of loop when a relation fails validation. All the foreign keys for the relation are set to the Error control state if they are input-capable. The following is a one section of the code from the Relation & view validation function:

Meta Loops are continued on the next page...

Go to: Top : Next page