CalcIt Commands

BUFDEF(FieldsList)

This command is used to create structure definitions to be used with Buffer variables. A structure definition is a list of field:field type pairs separated by commas. BUFDEF returns an ID that can be passed in Buffer variables definition/redefinition or on other BUFDEF commands.

const BufDefID=BUFDEF(Name:atCHAR[30],Amount:atINTEGER);

The above code returns a structure definition ID that represents a structure of two fields, Name (30 characters) and Amount (integer).

BUFDEF command is evaluated at compile time and for this reason its value can be assigned in a local constant. It is advised to use a local constants for a BUFDEF ID (and not a variable) because it can be used in another BUFDEF statement to define the type of a field (substructure). For example:

const BufDefID2=BUFDEF(f1:atCHAR[30],
                       f2:atINTEGER,
                       f3:atBUFFER(BufDefID));

Additionally a substructure field can be defined directly in a BUFDEF statement:

const BufDefID2=BUFDEF(f1:atCHAR[30],
                       f2:atINTEGER(100),
                       f3:atFLOAT,
                       f4:(a1:atINTEGER,
                           a2:atCHAR[50],
                           a3:atSHORT)
);

We can declare some fields to be arrays:

const BufDefID3=BUFDEF(f1:atCHAR[30],
                       f2:atINTEGER(100),
                       f3:atFLOAT);

The field f2 of type integer (atINTEGER) is an array of 100 elements.

We can create groups of fields that share the same memory address and memory space. In this case we use the UNION keyword and enclose the group of fields in parentheses as the example below demonstrates:

const DataType=BUFDEF(
                      Type:atINTEGER,
                      UNION(
                            s:atCHAR[20],
                            n:atFLOAT,
                            i:atINTEGER,
                            b:atBYTE
                           )
);

UNION groups can be nested and many such groups can be created in the same BUFDEF statement.

Consecutive fields of the same type can be declared in a more space saving syntax:

const DataType=BUFDEF(a1,a2,a3,a4:atINTEGER,
                      a5,a6
:atCHAR[50]);

BUFDEF can be used directly in the creation of a Buffer variable in a space saving syntax:

set bv=BUFDEF(f1:atCHAR[30],
              f2:atINTEGER(100),
              f3:atFLOAT);

For more information see Using Buffer variables.

Go Back