<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Check for valid interface?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/f02171a863/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/f02171a863/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/f02171a863/</id><updated>2022-01-29T11:30:55.467000Z</updated><subtitle>Recent posts to Check for valid interface?</subtitle><entry><title>Check for valid interface?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/f02171a863/?limit=25#2413" rel="alternate"/><published>2022-01-29T11:30:55.467000Z</published><updated>2022-01-29T11:30:55.467000Z</updated><author><name>i-campbell</name><uri>https://forge.codesys.com/u/i-campbell/</uri></author><id>https://forge.codesys.com2653604d223e0d73f844548de8549ddeceeda56a</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt;IF ItfFlushingPump &amp;lt;&amp;gt; 0 THEN&lt;/span&gt;
&lt;span class="err"&gt;   //OK&lt;/span&gt;
&lt;span class="err"&gt;END_IF&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;In the open source cobolt library, I have put in a GVL a function block instance g_InvalidMetric. So for most of the methods which return an IMetric, on error, they will return this global metric, rather thn nothing. This means, if you do want to call the methods anyway, it will not give you an exception, only invalid data.&lt;br/&gt;
In this case, you would look at the error message returned, or look at some property of the Interface to know if it is valid.&lt;/p&gt;
&lt;p&gt;Check out the Host Application in the Example Project of cobolt for how this looks.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Check for valid interface?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/f02171a863/?limit=25#81db" rel="alternate"/><published>2022-01-29T11:04:55.402000Z</published><updated>2022-01-29T11:04:55.402000Z</updated><author><name>somlioy</name><uri>https://forge.codesys.com/u/somlioy/</uri></author><id>https://forge.codesys.comf51ba54dfa952e86eda6101fe4ae51923593b930</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I have a common interface between various frequency drives (ItfDrive).&lt;br/&gt;
In a function block I have &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt;VAR_INPUT&lt;/span&gt;
&lt;span class="err"&gt;    ItfFlushingPump     : ItfDrive;&lt;/span&gt;
&lt;span class="err"&gt;END_VAR&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;How can I check that the interface is valid/has an assignment to an function block which has implemented this interface?&lt;br/&gt;
Is there some similar way as with references using __ISVALIDREF()?&lt;/p&gt;
&lt;p&gt;If no drive is assigned to the function block, and the function block is trying to access any properties or methods of the interface, it will crash ... That's what I want to avoid.&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>