<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to inheritance / extending a datatype</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7f8c3ce32c/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7f8c3ce32c/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/7f8c3ce32c/</id><updated>2020-05-17T05:52:38.354000Z</updated><subtitle>Recent posts to inheritance / extending a datatype</subtitle><entry><title>inheritance / extending a datatype</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7f8c3ce32c/?limit=25#7554" rel="alternate"/><published>2020-05-17T05:52:38.354000Z</published><updated>2020-05-17T05:52:38.354000Z</updated><author><name>Stefan</name><uri>https://forge.codesys.com/u/zatalian/</uri></author><id>https://forge.codesys.com3196e6ce2e0eb23faa2ee01de0555bf1648dc3f5</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I ended up using a array of an interface. Not intirely happy because i still need 2 array's (one for the objects, an other one for the interfaces), but it works&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/zatalian/conveyors" rel="nofollow"&gt;https://github.com/zatalian/conveyors&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>inheritance / extending a datatype</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7f8c3ce32c/?limit=25#205d" rel="alternate"/><published>2020-05-03T21:30:20.132000Z</published><updated>2020-05-03T21:30:20.132000Z</updated><author><name>JAPIB</name><uri>https://forge.codesys.com/u/japib/</uri></author><id>https://forge.codesys.com0835bc4b8f226693a4526857a5e3ac842ddd9bdb</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;My previous remark is still right, and you saw it with your example in C++&lt;br/&gt;
In any case, even with a pointer, if you try to move an array into another (whatever the type of data), the destination array must have the same structure as the source array.&lt;br/&gt;
When you use only the first source table level, it works well, because system take the two first element ( Position and Width) and forget the third, because destination table consist of 2 elements.&lt;br/&gt;
But when you use the entire table, system don't know how to fill destination table, because structures are different.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>inheritance / extending a datatype</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7f8c3ce32c/?limit=250#5766/6bec" rel="alternate"/><published>2020-05-03T11:49:27.232000Z</published><updated>2020-05-03T11:49:27.232000Z</updated><author><name>aliazzz</name><uri>https://forge.codesys.com/u/aliazzz/</uri></author><id>https://forge.codesys.com547b287d7c168deb1f0e4df507095c32e8ee7e05</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;If you are used to OOP in C++ or so, this should be a breeze.&lt;br/&gt;
There are however some exceptions on OOP usage in automation (PLC/DCS) systems.&lt;/p&gt;
&lt;p&gt;If you want a quick primer on OOP possibilities in CODESYS, try this:&lt;br/&gt;
&lt;a href="https://forge.codesys.com/prj/designpatterns/home/Home/"&gt;https://forge.codesys.com/prj/designpatterns/home/Home/&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>inheritance / extending a datatype</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7f8c3ce32c/?limit=25#5766" rel="alternate"/><published>2020-05-03T09:39:47.621000Z</published><updated>2020-05-03T09:39:47.621000Z</updated><author><name>Stefan</name><uri>https://forge.codesys.com/u/zatalian/</uri></author><id>https://forge.codesys.com856bfc2900a281f9bfe22c589e8d078b18ca84fa</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;ok, so an array puts the different objects directly behind each other in memory, so it is not possible to change the size (add or remove properties) of the individual object. I figured this out after trying the same thing in c++.&lt;/p&gt;
&lt;p&gt;BUT... even with an array of pointers to an object, it does not work... This should work, no?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>inheritance / extending a datatype</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7f8c3ce32c/?limit=25#d588" rel="alternate"/><published>2020-05-03T07:50:52.126000Z</published><updated>2020-05-03T07:50:52.126000Z</updated><author><name>Stefan</name><uri>https://forge.codesys.com/u/zatalian/</uri></author><id>https://forge.codesys.comea6b7d56da1cff37f5ed2e5de371ce09860f5331</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;isn't the whole point of extending a struct that an object of the extended struct is also considered as an object of the base struct?&lt;/p&gt;
&lt;p&gt;In my example, I want 1 fucntionblock to move objects. I would like this functionblock to be reusable to move any kind of object, either base or extended. I don't need the color of the box to move it.&lt;/p&gt;
&lt;p&gt;Instead of using your solution, where an array of boxes is converted into an array of objects, I can just as well write a second functionblock moveBoxes, defeating the whole point of extending my object...&lt;/p&gt;
&lt;p&gt;Note that if I create a functionblock MoveObject that moves 1 object, this idea holds:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nt"&gt;FUNCTION_BLOCK&lt;/span&gt; &lt;span class="nt"&gt;MoveObject&lt;/span&gt;
&lt;span class="nt"&gt;VAR_INPUT&lt;/span&gt;
    &lt;span class="nt"&gt;object&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;Object&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;
&lt;span class="nt"&gt;VAR_OUTPUT&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;
&lt;span class="nt"&gt;VAR&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;and&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nt"&gt;PROGRAM&lt;/span&gt; &lt;span class="nt"&gt;PLC_PRG&lt;/span&gt;
&lt;span class="nt"&gt;VAR&lt;/span&gt;
    &lt;span class="nt"&gt;boxes&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;ARRAY&lt;/span&gt;&lt;span class="cp"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="nx"&gt;..9&lt;/span&gt;&lt;span class="cp"&gt;]&lt;/span&gt; &lt;span class="nt"&gt;OF&lt;/span&gt; &lt;span class="nt"&gt;BOX&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nt"&gt;moveObjects&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;MoveObjects&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nt"&gt;moveObject&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;MoveObject&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;

&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nt"&gt;moveObjects&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;objects&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;boxes&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nt"&gt;moveObject&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;object&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;boxes&lt;/span&gt;&lt;span class="cp"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="cp"&gt;]&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;It is only when i start using arrays that it does not work anymore&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>inheritance / extending a datatype</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7f8c3ce32c/?limit=25#8065" rel="alternate"/><published>2020-05-02T23:12:06.683000Z</published><updated>2020-05-02T23:12:06.683000Z</updated><author><name>JAPIB</name><uri>https://forge.codesys.com/u/japib/</uri></author><id>https://forge.codesys.com1d60c70535392a4f93f77c498b3fe781d942501e</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;"cannot convert type 'ARRAY&lt;span&gt;[0..9]&lt;/span&gt; OF BOX' to type 'ARRAY&lt;span&gt;[*]&lt;/span&gt; OF Object"&lt;/p&gt;
&lt;p&gt;I think the  error is that you try to transfer an ARRAY of BOX into an ARRAY of Object.&lt;br/&gt;
But a BOX contains 3 elements (Position, Width, Color) and an Object contains only 2 elements (Position, Width) !  System don't know what to do with "Color" !!&lt;br/&gt;
You have to use a same type of ARRAY, or to transform Object type into Box Type.&lt;/p&gt;
&lt;p&gt;For example : &lt;/p&gt;
&lt;p&gt;FUNCTION_BLOCK Transform_Object_To_Box&lt;br/&gt;
VAR_INPUT&lt;br/&gt;
    END_VAR&lt;br/&gt;
VAR_OUTPUT&lt;br/&gt;
END_VAR&lt;br/&gt;
VAR_IN_OUT&lt;br/&gt;
    aObjects: ARRAY&lt;span&gt;[*]&lt;/span&gt; OF Object; (&lt;em&gt;source table&lt;/em&gt;)&lt;br/&gt;
    aBox:ARRAY&lt;span&gt;[*]&lt;/span&gt; OF Box; (&lt;em&gt;destination table&lt;/em&gt;)&lt;br/&gt;
END_VAR&lt;br/&gt;
VAR&lt;br/&gt;
    iIndice:DINT; (&lt;em&gt;Work index&lt;/em&gt;)&lt;br/&gt;
    diBegin:DINT; (&lt;em&gt;Start of table&lt;/em&gt;)&lt;br/&gt;
    diEnd:DINT;  (&lt;em&gt;End of table&lt;/em&gt;)&lt;br/&gt;
END_VAR&lt;br/&gt;
(&lt;em&gt;FB code&lt;/em&gt;)&lt;br/&gt;
(&lt;em&gt;Calculation of the dimensions of the table&lt;/em&gt;)&lt;br/&gt;
diBegin:=LOWER_BOUND(aObjects,1);&lt;br/&gt;
diEnd:=UPPER_BOUND(aObjects,1);&lt;/p&gt;
&lt;p&gt;(&lt;em&gt;Copy source table to destination table&lt;/em&gt;)&lt;br/&gt;
FOR iIndice:= diBegin TO diEnd DO&lt;br/&gt;
    aBox&lt;span&gt;[iIndice]&lt;/span&gt;.Position:=aBox&lt;span&gt;[iIndice]&lt;/span&gt;.Position;&lt;br/&gt;
    aBox&lt;span&gt;[iIndice]&lt;/span&gt;.Width:=aObjects&lt;span&gt;[iIndice]&lt;/span&gt;.Width;&lt;br/&gt;
    aBox&lt;span&gt;[iIndice]&lt;/span&gt;.Color:=0;&lt;br/&gt;
END_FOR&lt;/p&gt;
&lt;hr/&gt;
&lt;p&gt;PROGRAM PLC_PRG&lt;br/&gt;
VAR&lt;br/&gt;
    aInboxes: ARRAY&lt;span&gt;[0..9]&lt;/span&gt; OF Box; (&lt;em&gt;destination table&lt;/em&gt;)&lt;br/&gt;
    aInObjects: ARRAY&lt;span&gt;[0..9]&lt;/span&gt; OF Object; (&lt;em&gt;source table&lt;/em&gt;)&lt;br/&gt;
    Transform: Transform_Object_To_Box; &lt;br/&gt;
END_VAR&lt;/p&gt;
&lt;p&gt;(&lt;em&gt;PLC_PRG code&lt;/em&gt;)&lt;br/&gt;
Transform(aObjects:=aInObjects , aBox:=aInboxes );&lt;/p&gt;
&lt;p&gt;BR&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>inheritance / extending a datatype</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7f8c3ce32c/?limit=25#1cb0" rel="alternate"/><published>2020-05-01T06:58:52.628000Z</published><updated>2020-05-01T06:58:52.628000Z</updated><author><name>Stefan</name><uri>https://forge.codesys.com/u/zatalian/</uri></author><id>https://forge.codesys.com060f68e6d2784a94d552047c376ca3614212a826</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I'm trying to pass an array of an extended datatype as a VAR_IN_OUT to a funtionblock:&lt;/p&gt;
&lt;p&gt;I have a struct "Object":&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nt"&gt;TYPE&lt;/span&gt; &lt;span class="nt"&gt;Object&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt;
&lt;span class="nt"&gt;STRUCT&lt;/span&gt;
    &lt;span class="nt"&gt;Position&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;INT&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;-1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nt"&gt;Width&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;INT&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;END_STRUCT&lt;/span&gt;
&lt;span class="nt"&gt;END_TYPE&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;and i have an extended object "Box":&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nt"&gt;TYPE&lt;/span&gt; &lt;span class="nt"&gt;Box&lt;/span&gt; &lt;span class="nt"&gt;EXTENDS&lt;/span&gt; &lt;span class="nt"&gt;Object&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt;
&lt;span class="nt"&gt;STRUCT&lt;/span&gt;
    &lt;span class="nt"&gt;Color&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;INT&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;END_STRUCT&lt;/span&gt;
&lt;span class="nt"&gt;END_TYPE&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;I would like to pass an array of all kinds of object to a functionblock, for example:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nt"&gt;FUNCTION_BLOCK&lt;/span&gt; &lt;span class="nt"&gt;MoveObjects&lt;/span&gt;
&lt;span class="nt"&gt;VAR_INPUT&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;
&lt;span class="nt"&gt;VAR_OUTPUT&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;
&lt;span class="nt"&gt;VAR_IN_OUT&lt;/span&gt;
    &lt;span class="nt"&gt;objects&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;ARRAY&lt;/span&gt;&lt;span class="cp"&gt;[&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="cp"&gt;]&lt;/span&gt; &lt;span class="nt"&gt;OF&lt;/span&gt; &lt;span class="nt"&gt;Object&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;
&lt;span class="nt"&gt;VAR&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;But when i try to pass an array of boxes, i get a compile error:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nt"&gt;PROGRAM&lt;/span&gt; &lt;span class="nt"&gt;PLC_PRG&lt;/span&gt;
&lt;span class="nt"&gt;VAR&lt;/span&gt;
    &lt;span class="nt"&gt;boxes&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;ARRAY&lt;/span&gt;&lt;span class="cp"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="nx"&gt;..9&lt;/span&gt;&lt;span class="cp"&gt;]&lt;/span&gt; &lt;span class="nt"&gt;OF&lt;/span&gt; &lt;span class="nt"&gt;BOX&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nt"&gt;moveObj&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;MoveObjects&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;

&lt;span class="nt"&gt;moveObj&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;objects&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;boxes&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Last line gives me a "cannot convert type 'ARRAY&lt;span&gt;[0..9]&lt;/span&gt; OF BOX' to type 'ARRAY&lt;span&gt;[*]&lt;/span&gt; OF Object'. The error is not about the size of the array (0..9 vs *), but about the box and object. &lt;br/&gt;
How do i solve this?&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>