THIS and SUPER¶
THIS and SUPER name the function block instance a method is running
on. THIS^ is that instance itself; SUPER^ is the same instance seen
as its base type, which is how a derived type reaches an
inherited member it has hidden with one of its own. Both are pointers, so
both are written with the dereference operator ^.
Note
THIS and SUPER is a keyword only when the --allow-fb-inheritance flag is enabled. When the flag
is not set, THIS and SUPER is an ordinary identifier and may be used as a
variable or type name, exactly as in standard IEC 61131-3. Pass --allow-fb-inheritance to
enable the object-oriented syntax, or select a dialect that includes it.
See Enabling Dialects and Features for the dialects and
flags reference.
IEC 61131-3 |
Edition 3 (object-oriented programming) |
Support |
Parsed only — not yet analyzed or executed
(P9999). Enable with
|
Syntax¶
The dereference operator is required — THIS and SUPER are pointers,
so THIS.count is not valid where THIS^.count is. Whitespace between
the keyword and the ^ is accepted:
THIS ^ . member
SUPER ^ . member
A dereferenced reference is used wherever a variable is: read from, assigned to, subscripted, or called.
Example¶
FUNCTION_BLOCK FB_Motor
VAR
speed : INT;
END_VAR
METHOD Stop
THIS^.speed := 0;
END_METHOD
END_FUNCTION_BLOCK
FUNCTION_BLOCK FB_LoggingMotor EXTENDS FB_Motor
METHOD Stop
SUPER^.Stop();
END_METHOD
END_FUNCTION_BLOCK
FB_LoggingMotor declares its own Stop, which hides the one it
inherits. SUPER^.Stop() calls the hidden base implementation; writing
Stop() there would call itself.
THIS^ is most useful when a local name hides a member of the instance —
for example a method parameter named after a variable of the function block.
THIS^.speed then names the function block’s variable, and speed alone
names the parameter.
See Also¶
EXTENDS — derive from a base type
METHOD — declare a method on a function block type
ABSTRACT — mark a type as not directly instantiable
INTERFACE — declare an interface
Object Oriented Programming — inheritance, interfaces, and abstract types explained
FUNCTION_BLOCK — the
FUNCTION_BLOCKunit