L-force | plc designer – Lenze PLC Designer PLC Designer (R3-1) User Manual
Page 1087
L-force | PLC Designer
Programming Reference
DMS 4.1 EN 03/2011 TD29
1085
Syntax:
__QUERYINTERFACE(
The operator needs as first operand an interface reference or a function block instance
of the intended type and as second operand an interface reference. After execution of
__QUERYINTERFACE the ITF_Dest holds a reference to the intended interface if the
object referenced from ITF Source implements the interface. In this case the
conversion is successfully and the result of the operator returns TRUE. In all other cases
the operator returns FALSE.
Precondition for an explicit conversion is that not only the ITF_Source but also ITF Dest
is an extension of the interface __System.IQueryInterface. This interface is provided
implicitly and needs no library.
Example in ST:
INTERFACE ItfBase EXTENDS __System.IQueryInterface
METHOD mbase : BOOL
END_METHOD
INTERFACE ItfDerived1 EXTENDS __System.IQueryInterface
METHOD mderived1 : BOOL
END_METHOD
INTERFACE ItfDerived2 EXTENDS __System.IQueryInterface
METHOD mderived2 : BOOL
END_METHOD
PROGRAMM POU
VAR
itfderived1 : ItfDerived1;
itfderived2 : ItfDerived2;
bTest1, bTest2, xResult1, xResult2: BOOL;
END_VAR
xResult1 := __QUERYINTERFACE(itfbase, itfderived1); // variables of type ItfBase
resp. ItfDerived1
xResult2 := __QUERYINTERFACE(itfbase, itfderived2); // variables of type ItfBase
resp. ItfDerived2
IF (xResult1 = TRUE) THEN
bTest1 := itfderived1.mderived1();
ELSIF xResult2 THEN
bTest2 := itfderived2.mderived2();
END_IF