<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Basic OOP concept "instances" resp. "references"</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/25eb533a71/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/25eb533a71/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/25eb533a71/</id><updated>2020-02-27T13:54:01.447000Z</updated><subtitle>Recent posts to Basic OOP concept "instances" resp. "references"</subtitle><entry><title>Basic OOP concept "instances" resp. "references"</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/25eb533a71/?limit=25#1e8b" rel="alternate"/><published>2020-02-27T13:54:01.447000Z</published><updated>2020-02-27T13:54:01.447000Z</updated><author><name>schaepper</name><uri>https://forge.codesys.com/u/schaepper/</uri></author><id>https://forge.codesys.com056b01208291ef3329d5071860b25a914ac7d910</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hello everybody&lt;/p&gt;
&lt;p&gt;Thanks for your help, I finally found it yesterday. Interfaces are treated as pointer anyway so the declaration as POINTER TO or REFERENCE TO makes no sense resp. is not useful.&lt;br/&gt;
So if you want to use a FB as "fb instance", define in your input/output/method/property "fbinstance : POINTER TO FBType" .&lt;br/&gt;
Then you can pass the real pointer from the caller of an FB with ADR(fbinstance).The "opposite direction" would be the &lt;strong&gt;^&lt;/strong&gt;, so if you need to have the instance, instead of the pointer, often used if you refer to the instance with THIS, you will need the ^ so it doesnt take the pointer, it takes the instance.&lt;/p&gt;
&lt;p&gt;To hom it may be interessting:&lt;br/&gt;
The goal of our ErrorHanlder code is:&lt;br/&gt;
1. Encapsulate functionality to where it belongs to and have a "nice" architecture.&lt;br/&gt;
2. Maybe more important, we will have libraries in our company. So if you want to be able to still encapsulate the functionaly of errorhandling inside the error causing element/FB you need kind of an Interface to the element which effectifly handles the error. If your component is in a library, there is no filesystem where you can log to, therre is no HMI you can show your error, resp. you don't know where you will be running.&lt;/p&gt;
&lt;p&gt;In our case we startet with a motor. So if the motor runs, and there is something wrong it needs to raise an error and keep the error state. As soon as the error is gone, it can start again. (Could be a circuitbreaker or a VFD in overload, what ever). We in our company normaly want the user to commit an error, so the motor stays in errorstate as long as the user does not commit the error.&lt;/p&gt;
&lt;p&gt;For this we have 2 Interfaces:&lt;br/&gt;
- The AlarmHandlerInterface (this will be implemented by the FB which is actually resetting the error, making the decision if it has to be logged or viewed on a screen. And it handles user actions to reset the errors.&lt;br/&gt;
- The AlarmSourceInterface. This is needed because we want like a callback method to the error causing element so we can reset its errorstate.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nt"&gt;INTERFACE&lt;/span&gt; &lt;span class="nt"&gt;AlarmHandlerInterface&lt;/span&gt;
&lt;span class="o"&gt;(*&lt;/span&gt; &lt;span class="nt"&gt;------------------------------------&lt;/span&gt; &lt;span class="o"&gt;*)&lt;/span&gt;
&lt;span class="nt"&gt;METHOD&lt;/span&gt; &lt;span class="nt"&gt;RegisterAlarm&lt;/span&gt;
&lt;span class="nt"&gt;VAR_INPUT&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="nt"&gt;deviceWithAlarm&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="nt"&gt;AlarmSourceInterface&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;INTERFACE&lt;/span&gt; &lt;span class="n"&gt;AlarmSourceInterface&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="c1"&gt;------------------------------------ *)&lt;/span&gt;
&lt;span class="k"&gt;METHOD&lt;/span&gt; &lt;span class="n"&gt;ResetAlarm&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;If the Motor which implements AlarmSourceInterface needs to raise an alarm, it needs to call the RegisterAlarm method from the AlarmHandler which implements the AlarmHandlerInterface (and needs a type of AlarmSourceInterface in this signature). We in our case provided the AlarmHandler to the Motor in the FB_Init method (like a contstructor) so its only called once.&lt;/p&gt;
&lt;p&gt;The AlarmHanlder will then put the Motor into an internal list, like this:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;METHOD&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;RegisterAlarm&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="n"&gt;VAR_INPUT&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="n"&gt;deviceWithAlarm&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="n"&gt;AlarmSourceInterface&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="n"&gt;END_VAR&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;------------------------------------ *)&lt;/span&gt;
&lt;span class="n"&gt;devicesAlarmList&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;devicesInList&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;deviceWithAlarm&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="nl"&gt;devicesInList&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;devicesInList&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;In this case its a fixed Array with 100 elements, im sure its possible to improve this to a dynamic approach. Because normally you don't know how many items will be added and need to increase the size of the array / list dynamically.&lt;/p&gt;
&lt;p&gt;This code is called when for example the operator on a HMI pressed a button to commit all errors:&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;PUBLIC&lt;/span&gt; &lt;span class="nv"&gt;ResetAllAlarms&lt;/span&gt;
&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="o"&gt;------------------------------------&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nv"&gt;Resets&lt;/span&gt; &lt;span class="nv"&gt;all&lt;/span&gt; &lt;span class="nv"&gt;the&lt;/span&gt; &lt;span class="nv"&gt;alarms&lt;/span&gt; &lt;span class="nv"&gt;on&lt;/span&gt; &lt;span class="nv"&gt;each&lt;/span&gt; &lt;span class="nv"&gt;motor&lt;/span&gt;
&lt;span class="k"&gt;FOR&lt;/span&gt; &lt;span class="nv"&gt;currentDevice&lt;/span&gt;:&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="nv"&gt;TO&lt;/span&gt; &lt;span class="nv"&gt;devicesInList&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;DO&lt;/span&gt;
  &lt;span class="nv"&gt;devicesAlarmList&lt;/span&gt;[&lt;span class="nv"&gt;currentDevice&lt;/span&gt;].&lt;span class="nv"&gt;resetAlarm&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_FOR&lt;/span&gt;
&lt;span class="nv"&gt;devicesInList&lt;/span&gt;:&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;It goes through the array which has only items of type AlarmSourceInterface  in it and calls on each of this devices the reset alarm method.&lt;/p&gt;
&lt;p&gt;In the future we could also implement warnings and maybe sort of an autocommit depending if you use it.&lt;br/&gt;
In our case, the Interfaces and the Motor itself will be in the library. The AlarmHandler is in the project were your work is done.&lt;/p&gt;
&lt;p&gt;I will add the project for you so you can have a look into it. I also added pragmas so you see were you have to so something.&lt;/p&gt;
&lt;p&gt;Greetings and thanks a lot for your patience. I hope I can put more samples here in the future.&lt;/p&gt;
&lt;p&gt;&lt;a class="" href="https://forum.codesys.com//download/file.php?id=2912" rel="nofollow"&gt;BasicOOP_AlarmHandling.project &lt;span&gt;&lt;span&gt;[113.41 KiB]&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Basic OOP concept "instances" resp. "references"</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/25eb533a71/?limit=25#aa28" rel="alternate"/><published>2020-02-27T13:54:01.267000Z</published><updated>2020-02-27T13:54:01.267000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.com738030ac01e0eb43627c6a4066aa6625817e2402</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;em&gt;Originally created by:&lt;/em&gt; Viacheslav Mezentsev&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;schaepper hat geschrieben:&lt;/strong&gt;&lt;br/&gt;
I attached my latest project to this post if someone is interested.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Example works for me (Codesys 3.5.11.0). Maybe I'm don't understand something?&lt;/p&gt;
&lt;p&gt;&lt;a class="" href="https://forum.codesys.com//download/file.php?id=2903" rel="nofollow"&gt;BasicOOP.project &lt;span&gt;&lt;span&gt;[114.17 KiB]&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Basic OOP concept "instances" resp. "references"</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/25eb533a71/?limit=25#4a1d" rel="alternate"/><published>2020-02-27T13:54:01.099000Z</published><updated>2020-02-27T13:54:01.099000Z</updated><author><name>josepmariarams</name><uri>https://forge.codesys.com/u/josepmariarams/</uri></author><id>https://forge.codesys.comb96770bb32dd6ea00eb7eff50a89b91267d86c39</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi.&lt;/p&gt;
&lt;p&gt;Convert first your fb to an interface:&lt;/p&gt;
&lt;p&gt;A:Interface;&lt;br/&gt;
B:fb_ whichimplements interface&lt;/p&gt;
&lt;p&gt;B=A&lt;/p&gt;
&lt;p&gt;And pass b sa var_input.&lt;/p&gt;
&lt;p&gt;Codesys treates as pointers. If you see in debug B you can see the address of A littlel bit offseted.&lt;/p&gt;
&lt;p&gt;But if an fb waits for an interface as input, before you have to cast it.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Basic OOP concept "instances" resp. "references"</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/25eb533a71/?limit=25#a1e7" rel="alternate"/><published>2020-02-27T13:54:00.926000Z</published><updated>2020-02-27T13:54:00.926000Z</updated><author><name>Joan M</name><uri>https://forge.codesys.com/u/joan-m/</uri></author><id>https://forge.codesys.comd47b248a92ed002bedb03f820e9ac1ac1db6d765</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Check this one: &lt;a class="" href="https://stefanhenneken.wordpress.com/2014/11/16/iec-61131-6-abstract-factory-english/" rel="nofollow"&gt;https://stefanhenneken.wordpress.com/2014/11/16/iec-61131-6-abstract-factory-english/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This is a great post on how to create dynamic function blocks using interfaces with proper samples and not only pseudocodes.&lt;/p&gt;
&lt;p&gt;Of course I understand you, copies are not what you are after.&lt;/p&gt;
&lt;p&gt;In my sample I'm using pointers everywhere to update from outside data that exists on the pointed function block.  Unless I've made a mistake (more than possible given I've written the code directly here) it should work properly.&lt;/p&gt;
&lt;p&gt;See that article from Stefan which I guess it will give you some extra light on how to do it.&lt;/p&gt;
&lt;p&gt;Hope this helps.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Basic OOP concept "instances" resp. "references"</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/25eb533a71/?limit=25#2223" rel="alternate"/><published>2020-02-27T13:54:00.754000Z</published><updated>2020-02-27T13:54:00.754000Z</updated><author><name>schaepper</name><uri>https://forge.codesys.com/u/schaepper/</uri></author><id>https://forge.codesys.comc6e2e8e12774f12e1b92a1017267252b64e80564</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Joan M hat geschrieben:&lt;/strong&gt;&lt;br/&gt;
Check the last link I pasted in the first message, Stefan shows how to use interfaces correctly to get the most similar to what JAVA, C++, C# gives you.&lt;br/&gt;
In any case it is not important what interface you implement, you are passing the function block pointer (in my example pseudo code).&lt;br/&gt;
If you want to be able to use a more dynamic approach (given your background and the advantages it offers it is normal you would like to) then look at the Stefan link where good samples are implemented and deeply explained.&lt;br/&gt;
Hope this helps.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;You refering to this? &lt;a class="" href="https://stefanhenneken.wordpress.com/2014/02/18/iec-61131-3-object-composition-with-the-help-of-interfaces/" rel="nofollow"&gt;https://stefanhenneken.wordpress.com/20 ... nterfaces/&lt;/a&gt;&lt;br/&gt;
I read it completely, even time before but it does not (and in any article) explain the problem of "objects" always beeing copied if you don't use Reference To or similar approaches.&lt;/p&gt;
&lt;p&gt;If you don't use REFERENCE TO, POINTER TO or what ever if you just declare FB's as normal. And you pass a FB to another FB, and the "foreign" FB manipuliates the FB you are providing, he will manipulate the copy, not the FB you are providing.&lt;/p&gt;
&lt;p&gt;Here is my Pseudocode:&lt;br/&gt;
motor1.ManipulateCopyTestString('ManipulationFromOutside');&lt;br/&gt;
motor1(alarmHandler := alarmHandler1);&lt;br/&gt;
POU1(motorInput := motor1);&lt;/p&gt;
&lt;p&gt;//This is the Methodcall from POU1&lt;br/&gt;
motorInput.ManipulateCopyTestString('manipulatedinsideforeignfb');&lt;/p&gt;
&lt;p&gt;if you now look into "motor1" which was actually manipulated inside POU1, it will still have the string in it 'ManipulationFromOutside' which means POU1 manipulated a copy. And this is my Problem:&lt;/p&gt;
&lt;p&gt;Copy's don't make sense at all in an OOP aproach, and if I use pointers or references, I face the problems already describe in this post?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Basic OOP concept "instances" resp. "references"</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/25eb533a71/?limit=25#dfb3" rel="alternate"/><published>2020-02-27T13:54:00.201000Z</published><updated>2020-02-27T13:54:00.201000Z</updated><author><name>Joan M</name><uri>https://forge.codesys.com/u/joan-m/</uri></author><id>https://forge.codesys.come7cdb3cd76a261ed009d041fee74b8e6c39e8f0d</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Check the last link I pasted in the first message, Stefan shows how to use interfaces correctly to get the most similar to what JAVA, C++, C# gives you.&lt;/p&gt;
&lt;p&gt;In any case it is not important what interface you implement, you are passing the function block pointer (in my example pseudo code).&lt;/p&gt;
&lt;p&gt;If you want to be able to use a more dynamic approach (given your background and the advantages it offers it is normal you would like to) then look at the Stefan link where good samples are implemented and deeply explained.&lt;/p&gt;
&lt;p&gt;Hope this helps.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Basic OOP concept "instances" resp. "references"</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/25eb533a71/?limit=25#6c96" rel="alternate"/><published>2020-02-27T13:54:00.024000Z</published><updated>2020-02-27T13:54:00.024000Z</updated><author><name>Joan M</name><uri>https://forge.codesys.com/u/joan-m/</uri></author><id>https://forge.codesys.comf0f84664325f3182de0796dc614bfd2d56256505</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Yes, the problem is the type.&lt;/p&gt;
&lt;p&gt;You can't typecast pointers.&lt;/p&gt;
&lt;p&gt;In my code the pointer points to the function block type not to it's interface.&lt;/p&gt;
&lt;p&gt;In your code, given the name it looks like it points to the interface the function block implements.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Basic OOP concept "instances" resp. "references"</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/25eb533a71/?limit=25#6e49" rel="alternate"/><published>2020-02-27T13:53:59.846000Z</published><updated>2020-02-27T13:53:59.846000Z</updated><author><name>schaepper</name><uri>https://forge.codesys.com/u/schaepper/</uri></author><id>https://forge.codesys.com0393bc07d43bb3a272e3cc19408d184170b833c0</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Joan M hat geschrieben:&lt;/strong&gt;&lt;br/&gt;
pseudocode:&lt;br/&gt;
&lt;span&gt;[code]&lt;/span&gt;PROGRAM MAIN&lt;br/&gt;
VAR&lt;br/&gt;
  fbAlarmHandler : AH;&lt;br/&gt;
  fbMotor(ptrAlarmHandler := ADR(fbAlarmHandler));&lt;br/&gt;
END_VAR&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr/&gt;
&lt;p&gt;motor();  &lt;/p&gt;
&lt;p&gt;This is exactly the code that will not work because it sais:&lt;br/&gt;
Canot convert type "Pointer To AlarmHandler" to type "POINTER to AlarmHandlerInterface"&lt;/p&gt;
&lt;p&gt;This where all the post is about...&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Basic OOP concept "instances" resp. "references"</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/25eb533a71/?limit=25#4176" rel="alternate"/><published>2020-02-27T13:53:59.624000Z</published><updated>2020-02-27T13:53:59.624000Z</updated><author><name>Joan M</name><uri>https://forge.codesys.com/u/joan-m/</uri></author><id>https://forge.codesys.comeaf89a7ce143b5c810514cb8fcc3659d7700fd46</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;pseudocode:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;block&lt;/span&gt; &lt;span class="n"&gt;motor&lt;/span&gt;
&lt;span class="n"&gt;VAR_INPUT&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="n"&gt;ptrAlarmHandler&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;pointer&lt;/span&gt; &lt;span class="k"&gt;to&lt;/span&gt; &lt;span class="n"&gt;AH&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;END_VAR&lt;/span&gt;
&lt;span class="c1"&gt;--------------------------------------------------&lt;/span&gt;
&lt;span class="n"&gt;ptrAlarmHandler&lt;/span&gt;&lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ptrAlarmHandler&lt;/span&gt;&lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;block&lt;/span&gt; &lt;span class="n"&gt;AH&lt;/span&gt;
&lt;span class="n"&gt;VAR&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;END_VAR&lt;/span&gt;
&lt;span class="c1"&gt;-------------------------&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;PROGRAM&lt;/span&gt; &lt;span class="n"&gt;MAIN&lt;/span&gt;
&lt;span class="n"&gt;VAR&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="n"&gt;fbAlarmHandler&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;AH&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="n"&gt;fbMotor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ptrAlarmHandler&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ADR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fbAlarmHandler&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="n"&gt;END_VAR&lt;/span&gt;
&lt;span class="c1"&gt;-------------------------&lt;/span&gt;
&lt;span class="n"&gt;motor&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="k"&gt;After&lt;/span&gt; &lt;span class="n"&gt;executing&lt;/span&gt; &lt;span class="n"&gt;that&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="n"&gt;you&lt;/span&gt; &lt;span class="n"&gt;should&lt;/span&gt; &lt;span class="n"&gt;see&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="n"&gt;increasing&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;one&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Hope this helps.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Basic OOP concept "instances" resp. "references"</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/25eb533a71/?limit=25#08d9" rel="alternate"/><published>2020-02-27T13:53:59.455000Z</published><updated>2020-02-27T13:53:59.455000Z</updated><author><name>schaepper</name><uri>https://forge.codesys.com/u/schaepper/</uri></author><id>https://forge.codesys.com26f2b893fce2b78cc2d9eb0448a80403e727a5cf</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I tried it without the ^ but it still gives me the same alarm.&lt;/p&gt;
&lt;p&gt;"Remember that the pointers doesn't allow typecasting here, if you define a pointer to a specific type you can't pass a different pointer there."&lt;/p&gt;
&lt;p&gt;What would be the solution? Just as an info: My goal is not to use references, or pointers, whatever I just want to pass the same instance of a FB around. If I do it the "classic" way without pointers,refs or anything then the FB's always get copied on asignments. I just want to overcome the copies.&lt;/p&gt;
&lt;p&gt;Basically I just want to use it like every other "OOP" language in the field like C#,JAVA,Python,C++ what ever...&lt;/p&gt;
&lt;p&gt;I attached my latest project to this post if someone is interested.&lt;/p&gt;
&lt;p&gt;&lt;a class="" href="https://forum.codesys.com//download/file.php?id=2902" rel="nofollow"&gt;BasicOOP.project &lt;span&gt;&lt;span&gt;[114.17 KiB]&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>