Accessing Header Information

23.08.2021

FlexPro can append a data object Header Information reference to an FPScript value that originates from this data object. You can therefore access the data object's attributes via the value. The header information is the properties of the ValueObject object, including the parameter list. If an FPScript value is passed as an argument or as a return value from a value in a different formula, then the value can be used to access the header information without an object reference. FlexPro uses this header information assigned to the data for such tasks as labeling axes in a diagram.

When assigning the header information of a formula to its result value, FlexPro takes into account the Header Information setting on the Results tab of the formula. There you can set whether the header information should only be added or whether existing header information should be replaced or removed.

FPScript functions which only modify the data passed as an argument, such as filter functions, pass the header information from the argument to your result. The same applies to index operations for selecting a data component or a list element.

The following code uses the variable x to access the X component comments of the data set containing the x value:

Dim x = \Data\DataSet

x.CommentsX

You can also have write-access to an attribute:

x.CommentsX = "Time"

x.UpperRangeLimitX = 1.3

Write access in this case is not to the data object upon which it is based (\Data\DataSet in the example above). Instead, x is assigned a local copy for the property to be changed. This copy is then set to the assigned value. You can delete the local copy by deleting the associated property:

x.CommentsX = ""

x.UpperRangeLimitX = ?

The associated attributes will then be removed from the data set at the next read access attempt.

Parameters

The complete parameter list is always provided as a local copy. If when using write access a name is specified that does not have any parameters, the name will be created automatically.

x.Parameters("MyParam") = 1.3

Apply the Empty value to delete a parameter again:

x.Parameters("MyParam") = Empty

You can verify whether a parameter is in the list using the Index property. The result will be 0 if it is not.

x.Parameters.Index("MyParam")

Read access to a parameter only results in its value. You need to read out and assign the unit separately:

ChangeUnit(x.Parameters("MyParam"), x.Parameters("MyParam").Unit)

Calculations

Only read access is available for calculations. Read access to a calculation only results in its value. You need to read out and assign the unit separately:

ChangeUnit(x.Calculations("MyCalculation"), x.Calculations("MyCalculation").Unit)

You can verify whether a calculation is in the list using the Index property. The result will be 0 if it is not.

x.Calculations.Index("MyCalculation")

Lists

Forms that provide a list with multiple data sets as the result are a special feature. If the formula bundles only data sets into a list, the list elements obtain the header information of the data sets from which they originate:

Dim x = [Signal1, Signal2]
x.[0].Name    results in "Signal1"

Note: If you return this type of list as a formula result and do not want the header information to be overwritten by that of the formula, you will have to choose the following in the Header Information list box on the Results tab of the formula Properties dialog box: Automatic, Only assign if not already present or Never assign.

If the formula calculates a result and the result is returned as a list, you will have to set how to name list elements under List Element Names on the Results tab of the formula. The list element names of the calculated source data are often built into the result's list element names and therefore are known to FlexPro. This is done by assigning the source data of the local variable SourceData. FlexPro takes this into account when assigning element names after calculating the formula.

Dim SourceData = [Signal1, Signal2]
Integral(SourceData)

x.[0].Name    results in "Signal1Integral", if on formula the Results tab, the option Automatic is set and the formula itself is called "Integral".

x.[0].CommentsX    If on the Results tab of the formula the option Always assign is set, the expression result provides the X comments of the formula containing the FPScript code. Otherwise, the result provides the X comments of the Signal1 data set, since the Integral function passes this in its result.

Components

If an FPScript variable contains a component of an aggregate data set, then the component is used as the template for the properties for which a component can be specified optionally as the argument if you omit the argument:

Dim x = DataSet.X

x.Quantity    corresponds to DataSet.Quantity(fpDataComponentX)

It is therefore easy to access the attributes of each relevant component.

You might be interested in these articles