Member Qualifiers¶
A member qualifier is a word between FUNCTION_BLOCK or METHOD and
the name that says who may use the declaration (PUBLIC, PRIVATE,
PROTECTED, INTERNAL) or how a derived type may treat it
(FINAL, OVERRIDE, ABSTRACT). Qualifiers are part
of the object-oriented programming introduced in IEC 61131-3 Edition 3, and
CODESYS and TwinCAT use the same words.
Note
Except for ABSTRACT, the qualifiers are never keywords. A word is
taken as a qualifier only between FUNCTION_BLOCK or METHOD and
the name, so Final or Override can still be a variable, method
or function block name. A qualifier on a function block needs
--allow-fb-inheritance and reports
P4062 without it. See
Enabling Dialects and Features for the flags and
dialects reference.
IEC 61131-3 |
Edition 3 (object-oriented programming) |
Support |
Parsed and checked: a combination, order or position that TwinCAT
rejects reports P4063.
The qualifiers are not enforced otherwise. A |
Syntax¶
FUNCTION_BLOCK [access_specifier] [FINAL | ABSTRACT] fb_name ...
METHOD [access_specifier] [FINAL | ABSTRACT] [OVERRIDE] method_name [: return_type] ...
access_specifier ::= PUBLIC | PRIVATE | PROTECTED | INTERNAL
The rules, checked against TwinCAT 3.1.4024:
A qualifier appears at most once, and there is at most one access specifier (
PUBLIC,PRIVATE,PROTECTED,INTERNAL).The access specifier comes first, before
FINAL,ABSTRACTandOVERRIDE.METHOD FINAL PUBLIC Mis an error;METHOD PUBLIC FINAL Mis not.FINALandABSTRACTexclude each other.A function block cannot be
PRIVATE,PROTECTEDorOVERRIDE.An
ABSTRACTmethod has no body, and only anABSTRACTfunction block can declare one.
Each rule that is broken reports P4063.
Example¶
FUNCTION_BLOCK PUBLIC ABSTRACT FB_Axis
VAR
position : REAL;
END_VAR
METHOD PUBLIC ABSTRACT MoveTo
VAR_INPUT
target : REAL;
END_VAR
END_METHOD
METHOD PRIVATE Clamp
IF position < 0.0 THEN
position := 0.0;
END_IF;
END_METHOD
END_FUNCTION_BLOCK
MoveTo has no body; a function block that
extends FB_Axis provides it. Clamp is meant for
use inside FB_Axis only.