Dynamic variables

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

Dynamic variables

mapp Services V5.16

Navigation over dynamic data is supported using dereference operator "^". This operator is used to continue a variable reference through levels of "REFERENCE TO" data types if automatic dereferencing is not enabled.

Reference variables are automatically dereferenced.

Structure members are not dereferenced.

Example

TYPE
  Tool : STRUCT
    id : DINT;
    radius : LREAL;
  END_STRUCT;
  ToolSet : STRUCT
    main : Tool;
    alt : REFERENCE TO Tool;
  END_STRUCT;
END_TYPE
VAR
  Ts : ToolSet;
  Tptr : REFERENCE TO ToolSet;
END_VAR
PROGRAM _MAIN
  (* Configure REFERENCE TO addresses *)
  Tptr ACCESS ADR(Ts);  (* Use ACCESS for auto-dereferenced variable *)
  Tptr.alt := ADR(Tptr.main);
  (* Access through REFERENCE TO data members *)
  Tptr.alt^.id := 1;
END_PROGRAM

Navigation

Data type

Notes

Tptr

ToolSet

Automatically dereferenced (points to Ts)

Tptr.main

Tool

 

Tptr.alt

REFERENCE TO tool

Pointer to tool (in Ts.main)

Tptr.alt^

Tool

Tool data from Ts.main

Tptr.main.id

DINT

 

Tptr.alt^.id

DINT

Navigates across the reference