Structures¶
Structures are created as objects in the Object Organizer under the register card Data types. They begin with the keywords TYPE and STRUCT and end with END_STRUCT and END_TYPE.
The syntax for structure declarations is as follows:
TYPE <Structurename>:
STRUCT
<Declaration of Variables 1>
.
.
<Declaration of Variables n>
END_STRUCT
END_TYPE
<Structurename> is a type that is recognized throughout the project and can be used like a standard data type.
Interlocking structures are allowed. The only restriction is that variables may not be placed at addresses (the AT declaration is not allowed!).
Example for a structure definition named Polygonline:
TYPE Polygonline:
STRUCT
Start:ARRAY [1..2] OF INT;
Point1:ARRAY [1..2] OF INT;
Point2:ARRAY [1..2] OF INT;
Point3:ARRAY [1..2] OF INT;
Point4:ARRAY [1..2] OF INT;
End:ARRAY [1..2] OF INT;
END_STRUCT
END_TYPE
Example for the initialization of a structure:
Poly_1:polygonline := ( Start:=3,3, Point1 =5,2, Point2:=7,3, Point3:=8,5, Point4:=5,7, End := 3,5);
Initializations with variables are not possible. See an example of the initialization of an array of a structure under ‘Arrays’.
Access on structure components:
You can gain access to structure components using the following syntax:
<Structure_Name>.<Componentname>
So for the above mentioned example of the structure ‘polygonline’ you can access the component ‘start’ by Poly_1.Start
.