Method invocation, L-force | plc designer – Lenze PLC Designer PLC Designer (R3-1) User Manual

Page 79

Advertising
background image

L-force | PLC Designer

Concepts and Base Components

DMS 4.1 EN 03/2011 TD29

77

Now consider a declaration of a variable of type I1:

FUNCTION DeliverName : STRING
VAR_INPUT
l_i : I1;
END_VAR

This input can receive all function blocks that implement interface I1.
Example for function calls:

DeliverName(l_i := A_instance); // call with instance of type A
DeliverName(l_i := B_instance); // call with instance of type B

Note that a variable of an interface-type...
... must get assigned an instance of a function block before a method can be called on
it.
... always is a reference to the assigned function block instance. Thus a call to the
interface method does result in a call to the function block implementation. As soon as
the reference is assigned, the corresponding address will be monitored in online mode.
Otherwise, if no reference has been assigned yet, the value 0 will be shown within
monitoring in online mode.
Example:
in the implementation part of the above described function "DeliverName":

DeliverName := l_i.GetName(); // in this case it depends on the "real" type of l_i
whether A.GetName or B.GetName is called.

Note: See also the possibility to extend a function block by using keyword EXTENDS
in the declaration.

Method invocation
Object oriented programming
with function blocks is - besides of the possibility of
extension via EXTENDS - supported by the possible use of interfaces and inheritance.
This requires dynamically resolved method invocations, also called "virtual function
calls".
See Method for further information on methods.
Virtual function calls need some more time than normal function calls and are used
when:
• a call is performed via a pointer to a function block (pfub^.method)
• a method of an interface variable is called (interface1.method)
• a method calls another method of the same function block
Virtual function calls make possible that the same call in a program source code will
invoke different methods during runtime.

Advertising