EcoStruxure Machine Expert version 1.1 does not support the M258, LMC058 and LMC078 controllers.

__QUERYINTERFACE

Definition

This operator is not prescribed by the IEC 61131-3 standard.

At runtime, __QUERYINTERFACE is enabling a type conversion of an interface reference to another. The operator returns a result with type BOOL. TRUE implies, that the conversion is successfully executed.

Syntax

__QUERYINTERFACE(<ITF_Source>, < ITF_Dest>

The operator needs as the first operand an interface reference or a function block instance of the intended type and as second operand an interface reference. After execution of __QUERYIN­TERFACE, 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 successful and the result of the operator returns TRUE. In all other cases, the operator returns FALSE.

A 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

Example in ST:

INTERFACE ItfBase EXTENDS __System.IQueryInterface
METHOD mbase : BOOL
END_METHOD
INTERFACE ItfDerived1 EXTENDS ItfBase
METHOD mderived1 : BOOL
END_METHOD
INTERFACE ItfDerived2 EXTENDS ItfBase
METHOD mderived2 : BOOL
END_METHOD
FUNCTION_BLOCK FB1 IMPLEMENTS ItfDerived1
METHOD mbase : BOOL 
    mbase := TRUE;
END_METHOD 
METHOD mderived1 : BOOL 
    mderived1 := TRUE;
END_METHOD 
END_FUNCTION_BLOCK
FUNCTION_BLOCK FB2 IMPLEMENTS ItfDerived2
METHOD mbase : BOOL 
    mbase := FALSE;
END_METHOD 
METHOD mderived2 : BOOL 
    mderived2 := TRUE;
END_METHOD 
END_FUNCTION_BLOCK
PROGRAM POU
VAR
    inst1 : FB1;
    inst2 : FB2;
    itfbase1 : ItfBase := inst1;
    itfbase2 : ItfBase := inst2;
    itfderived1 : ItfDerived1 := 0;
    itfderived2 : ItfDerived2 := 0;
    bTest1, bTest2, xResult1, xResult2: BOOL;
END_VAR
xResult1 := __QUERYINTERFACE(itfbase1, itfderived1); // xResult = TRUE, itfderived1 <> 0
                                      // references the instance inst1
xResult2 := __QUERYINTERFACE(itfbase1, itfderived2); // xResult = FALSE, itfderived2 = 0
xResult3 := __QUERYINTERFACE(itfbase2, itfderived1); // xResult = FALSE, itfderived1 = 0
xResult4 := __QUERYINTERFACE(itfbase2, itfderived2); // xResult = TRUE, itfderived2 <> 0
                                      // references the instance inst2