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.
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:
Additionally a substructure field can be defined directly in a BUFDEF statement:
We can declare some fields to be arrays:
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:
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:
BUFDEF can be used directly in the creation of a Buffer variable in a space saving syntax:
For more information see Using Buffer variables.