<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Check class relationship</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7949adee11/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7949adee11/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/7949adee11/</id><updated>2020-02-27T13:48:09.255000Z</updated><subtitle>Recent posts to Check class relationship</subtitle><entry><title>Check class relationship</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7949adee11/?limit=25#7f7b" rel="alternate"/><published>2020-02-27T13:48:09.255000Z</published><updated>2020-02-27T13:48:09.255000Z</updated><author><name>Omar Ampyx</name><uri>https://forge.codesys.com/u/omar-ampyx/</uri></author><id>https://forge.codesys.com64c0faae3fee070c94f05fb479dc156d1fc597c9</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi there,&lt;/p&gt;
&lt;p&gt;I changed the approach so that I don't have this issue anymore.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br/&gt;
Omar&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Check class relationship</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7949adee11/?limit=25#b25f" rel="alternate"/><published>2020-02-27T13:48:09.195000Z</published><updated>2020-02-27T13:48:09.195000Z</updated><author><name>Omar Ampyx</name><uri>https://forge.codesys.com/u/omar-ampyx/</uri></author><id>https://forge.codesys.comfe349b654dea7401cf97c9fafb7e280d38494d7e</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Dear alb123,&lt;/p&gt;
&lt;p&gt;Thanks for replying. I am confused with your second example, shouldn't it be the other way around like in the first example? My understanding is that it is allowed to point to a child class where a parent type is expected but not the other way around?&lt;/p&gt;
&lt;p&gt;I think your example is of no use to me, because in my case the pointer to be checked is not known. More specifically, the reference to be checked (which is initally defined as a reference to a base class) can be referenced to any child class at the implementation and the compiler will be happy about it:&lt;/p&gt;
&lt;p&gt;VAR&lt;br/&gt;
  rReferenceToBeChecked  REFERENCE TO CLS_BaseClass &lt;br/&gt;
END_VAR&lt;/p&gt;
&lt;p&gt;IMPLEMENTATION CASE 1&lt;br/&gt;
 rReferenceToBeChecked  REF=clsInstanceOfBaseClass&lt;/p&gt;
&lt;p&gt;IMPLEMENTATION CASE 2 &lt;br/&gt;
 rReferenceToBeChecked  REF=clsInstanceOfChildClass&lt;/p&gt;
&lt;p&gt;At this point what I want is to ensure that the developer has supplied a child class (case 2) and generate an error if otherwise. That is why my intention is to confirm whether rReferenceToBeChecked is a subclass of a CLS_BaseClass.&lt;/p&gt;
&lt;p&gt;Thank you in advance,&lt;br/&gt;
Omar&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Check class relationship</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7949adee11/?limit=25#bb07" rel="alternate"/><published>2020-02-27T13:48:09.131000Z</published><updated>2020-02-27T13:48:09.131000Z</updated><author><name>Omar Ampyx</name><uri>https://forge.codesys.com/u/omar-ampyx/</uri></author><id>https://forge.codesys.comc9bec414f8a4a7efe63e2bb28d6cacb191d8b079</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;sorry I submitted this by accident.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Check class relationship</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7949adee11/?limit=25#645f" rel="alternate"/><published>2020-02-27T13:48:08.774000Z</published><updated>2020-02-27T13:48:08.774000Z</updated><author><name>alb123</name><uri>https://forge.codesys.com/u/alb123/</uri></author><id>https://forge.codesys.com4053d0fbf50277d3a664262dda278a70d309e293</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;As far as I know there is no function as easy as issubclass().&lt;br/&gt;
&lt;a class="" href="https://help.codesys.com/webapp/_cds_operator_querypointer;product=codesys;version=3.5.13.0" rel="nofollow"&gt;https://help.codesys.com/webapp/_cds_operator_querypointer;product=codesys;version=3.5.13.0&lt;/a&gt;&lt;br/&gt;
Using querypointer you have to know which sublass you are looking for.&lt;/p&gt;
&lt;p&gt;Your base class must implement __SYSTEM.IQueryInterface&lt;/p&gt;
&lt;p&gt;I put together the following test of this function a while a go in e!cockpit:&lt;/p&gt;
&lt;p&gt;First defined FB_animal, FB_Cat, and FB_Dog&lt;/p&gt;
&lt;p&gt;I was then able to test like this:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nv"&gt;METHOD&lt;/span&gt; &lt;span class="nv"&gt;MakeSound&lt;/span&gt; : &lt;span class="nv"&gt;STRING&lt;/span&gt;
&lt;span class="nv"&gt;VAR_INPUT&lt;/span&gt;
   &lt;span class="nv"&gt;pAnimal&lt;/span&gt; : &lt;span class="nv"&gt;POINTER&lt;/span&gt; &lt;span class="nv"&gt;TO&lt;/span&gt; &lt;span class="nv"&gt;FB_Animal&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;END_VAR&lt;/span&gt;
&lt;span class="nv"&gt;VAR&lt;/span&gt;
   &lt;span class="nv"&gt;pCat&lt;/span&gt; : &lt;span class="nv"&gt;POINTER&lt;/span&gt; &lt;span class="nv"&gt;TO&lt;/span&gt; &lt;span class="nv"&gt;FB_CAT&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
   &lt;span class="nv"&gt;pDog&lt;/span&gt; : &lt;span class="nv"&gt;POINTER&lt;/span&gt; &lt;span class="nv"&gt;TO&lt;/span&gt; &lt;span class="nv"&gt;FB_Dog&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
   &lt;span class="nv"&gt;sRespons&lt;/span&gt; : &lt;span class="nv"&gt;STRING&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;END_VAR&lt;/span&gt;
&lt;span class="k"&gt;IF&lt;/span&gt; &lt;span class="nv"&gt;__QUERYPOINTER&lt;/span&gt; &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;pAnimal&lt;/span&gt;&lt;span class="o"&gt;^&lt;/span&gt;,&lt;span class="nv"&gt;pCat&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt;
   &lt;span class="nv"&gt;MakeSound&lt;/span&gt; :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;pCat&lt;/span&gt;&lt;span class="o"&gt;^&lt;/span&gt;.&lt;span class="nv"&gt;Mjau&lt;/span&gt;&lt;span class="ss"&gt;()&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;END_IF&lt;/span&gt;
&lt;span class="k"&gt;IF&lt;/span&gt; &lt;span class="nv"&gt;__QUERYPOINTER&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;pAnimal&lt;/span&gt;&lt;span class="o"&gt;^&lt;/span&gt;, &lt;span class="nv"&gt;pDog&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt;
   &lt;span class="nv"&gt;MakeSound&lt;/span&gt; :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;pDog&lt;/span&gt;&lt;span class="o"&gt;^&lt;/span&gt;.&lt;span class="nv"&gt;Bark&lt;/span&gt;&lt;span class="ss"&gt;()&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;END_IF&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;If you are testing if an instance of FB_Dog is a subclass of FB_Animal I believe you could define a POINTER TO FB_Animal and use __Querypointer. I have not tested this&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;IF&lt;/span&gt; &lt;span class="nv"&gt;__QUERYPOINTER&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;fbDog&lt;/span&gt;, &lt;span class="nv"&gt;pAnimal&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt;
   &lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nv"&gt;It&lt;/span&gt; &lt;span class="nv"&gt;is&lt;/span&gt; &lt;span class="nv"&gt;possible&lt;/span&gt; &lt;span class="nv"&gt;to&lt;/span&gt; &lt;span class="nv"&gt;point&lt;/span&gt; &lt;span class="nv"&gt;to&lt;/span&gt; &lt;span class="nv"&gt;fbDog&lt;/span&gt; &lt;span class="nv"&gt;using&lt;/span&gt; &lt;span class="nv"&gt;POINTER&lt;/span&gt; &lt;span class="nv"&gt;TO&lt;/span&gt; &lt;span class="nv"&gt;FB_Animal&lt;/span&gt;. &lt;span class="nv"&gt;It&lt;/span&gt; &lt;span class="nv"&gt;must&lt;/span&gt; &lt;span class="nv"&gt;be&lt;/span&gt; &lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;subclass&lt;/span&gt; &lt;span class="nv"&gt;of&lt;/span&gt; &lt;span class="nv"&gt;animals&lt;/span&gt;
&lt;span class="nv"&gt;END_IF&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</summary></entry><entry><title>Check class relationship</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7949adee11/?limit=25#0af6" rel="alternate"/><published>2020-02-27T13:48:08.703000Z</published><updated>2020-02-27T13:48:08.703000Z</updated><author><name>Omar Ampyx</name><uri>https://forge.codesys.com/u/omar-ampyx/</uri></author><id>https://forge.codesys.com97c99e296e880d29e85a6f9f10185772a561a124</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi everyone,&lt;/p&gt;
&lt;p&gt;Is there a function or way to check whether a class instance is a subclass of a class? Sorry for the alliteration   &lt;/p&gt;
&lt;p&gt;Something similar to issubclass() in Phyton.&lt;/p&gt;
&lt;p&gt;Thank you in advance,&lt;br/&gt;
Omar&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>