__QUERYPOINTER
The operator is an extension of IEC61131-3.
The operator enables type conversion of an interface reference of a function block to a pointer at runtime. The operator returns a result of type BOOL. TRUE means that TwinCAT performed the conversion successfully.
For compatibility reasons, the definition of the pointer to be converted must be an extension of the basic interface __SYSTEM.IQueryInterface. |
Syntax: __QUERYPOINTER (<ITF_Source>, <Pointer_Dest>)
The first operand assigned to the operator is an interface reference or an FB instance with the desired target types, the second operand is a pointer. After __QUERYPOINTER has been processed, Pointer_Dest contains the pointer to the reference or instance of a function block, to which the interface reference ITF_Source currently points. Pointer_Dest is not typed and can be cast to any type. Make sure the type is correct. For example, the interface could offer a method that returns a type code.
Example:
Interfaces:
INTERFACE I_Base EXTENDS __System.IQueryInterface
METHOD Base : BOOL
INTERFACE I_Derived EXTENDS I_Base
METHOD Derived : BOOL
Function block:
FUNCTION_BLOCK FB_Variante IMPLEMENTS I_Derived
METHOD Base : BOOL
METHOD Derived : BOOL
Program:
PROGRAM MAIN
VAR
iDerived : I_Derived;
fbVariante : FB_Variante;
bResult : BOOL;
bTest : BOOL;
pFB : POINTER TO FB_Variante;
END_VAR
iDerived := fbVariante;
bResult := __QUERYPOINTER(iDerived, pFB);
IF bResult THEN
bTest := pFB^.Derived();
END_IF