<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Using pointer to action/method</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/4187717df3/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/4187717df3/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/4187717df3/</id><updated>2022-03-03T22:20:33.226000Z</updated><subtitle>Recent posts to Using pointer to action/method</subtitle><entry><title>Using pointer to action/method</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/4187717df3/?limit=25#6d90/54b5/1c8a/1874/5503" rel="alternate"/><published>2022-03-03T22:20:33.226000Z</published><updated>2022-03-03T22:20:33.226000Z</updated><author><name>fajean</name><uri>https://forge.codesys.com/u/fajean/</uri></author><id>https://forge.codesys.com027093a14c3a333bfcb1e61c5717d7ad344f7080</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I guess it is!  Passing methods by address or using lambda expression (which is a nicer way to to something similar) also would be, if not rigorously speaking, at least from a modelling point of view.  I am not a scholar, I have just been programming for decades in various languages, so there are concepts that are entirely clear in my mind for which I do not use the vocabulary from textbooks.  I write code, not slides or presentations, the compiler/interpreter is my audience... :)&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Using pointer to action/method</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/4187717df3/?limit=250#6d90/54b5/1c8a/1874" rel="alternate"/><published>2022-03-03T21:50:48.263000Z</published><updated>2022-03-03T21:50:48.263000Z</updated><author><name>h-hermsen</name><uri>https://forge.codesys.com/u/hermsen/</uri></author><id>https://forge.codesys.com24fc9b5d3eb3e5b6f0fc42a64f5d2f8136d21455</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Isn't this called "dependancy injection"?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Using pointer to action/method</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/4187717df3/?limit=25#6d90/54b5/1c8a" rel="alternate"/><published>2022-03-03T20:20:06.371000Z</published><updated>2022-03-03T20:20:06.371000Z</updated><author><name>fajean</name><uri>https://forge.codesys.com/u/fajean/</uri></author><id>https://forge.codesys.comabfd310891ba7ae5914f05b74ddfeaf38dea1619</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Although you cannot pass the address of a method and there are no lambda expressions in CODESYS, you can pass a pointer/reference of the outer function block to the inner function block, or pass the parent FB in the form of an instance of an interface the outer function block implements. Although it may not be your preferred idiom, I am not sure why you think it would not work.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Using pointer to action/method</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/4187717df3/?limit=250#4879/c257" rel="alternate"/><published>2022-03-03T14:21:39.788000Z</published><updated>2022-03-03T14:21:39.788000Z</updated><author><name>h-hermsen</name><uri>https://forge.codesys.com/u/hermsen/</uri></author><id>https://forge.codesys.com9d01393218ea76a7210097bfa21e33909a7e2f15</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;"I came from Python where this things are daily basics" =&amp;gt; ? AFAIK Python doesn't implement Interfaces. It only sports classes which implement methods/properties direct.&lt;/p&gt;
&lt;p&gt;"sorry for asking something out of the codesys world" =&amp;gt;&lt;br/&gt;
Why are you sorry?&lt;/p&gt;
&lt;p&gt;"What I was trying to do is a multiple uses block"  =&amp;gt;  Please try to explain your question more thorough, if you can explain it well, we can surely help you find an anwser.&lt;/p&gt;
&lt;p&gt;Besides that, I strongly advise against building a "multiple uses block" as it surely goes against the SOLID  Single responsibility principle of ONE object should only do ONE task(!) &lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Using pointer to action/method</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/4187717df3/?limit=25#4879" rel="alternate"/><published>2022-03-03T14:05:09.397000Z</published><updated>2022-03-03T14:05:09.397000Z</updated><author><name>adrian</name><uri>https://forge.codesys.com/u/adrian/</uri></author><id>https://forge.codesys.comccc518d53b66140eb37ca9ff4c0c3b9595c43ce1</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Ok, seeing your answers I think I can't do what I wanted to do.&lt;br/&gt;
I came from Python where this things are daily basics, sorry for asking something out of the codesys world.&lt;br/&gt;
Interfaces are good and I used it a lot, but it are meant to work with related objects, what I was trying to do is a multiple uses block, something that maybe I could post as a library. Thanks anyway!&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Using pointer to action/method</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/4187717df3/?limit=25#1348" rel="alternate"/><published>2022-03-03T14:05:06.965000Z</published><updated>2022-03-03T14:05:06.965000Z</updated><author><name>adrian</name><uri>https://forge.codesys.com/u/adrian/</uri></author><id>https://forge.codesys.com05b1300360863a4102fb52fedb7cd98feb15f028</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Ok, seeing your answers I think I can't do what I wanted to do.&lt;br/&gt;
I came from Python where this things are daily basics, sorry for asking something out of the codesys world.&lt;br/&gt;
Interfaces are good and I used it a lot, but it are meant to work with related objects, what I was trying to do is a multiple uses block, something that maybe I could post as a library. Thanks anyway!&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Using pointer to action/method</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/4187717df3/?limit=25#5c9a" rel="alternate"/><published>2022-03-03T14:05:06.360000Z</published><updated>2022-03-03T14:05:06.360000Z</updated><author><name>adrian</name><uri>https://forge.codesys.com/u/adrian/</uri></author><id>https://forge.codesys.comaf7abe6393a49d903ffa9f2bb93ec792ff50f507</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Ok, seeing your answers I think I can't do what I wanted to do.&lt;br/&gt;
I came from Python where this things are daily basics, sorry for asking something out of the codesys world.&lt;br/&gt;
Interfaces are good and I used it a lot, but it are meant to work with related objects, what I was trying to do is a multiple uses block, something that maybe I could post as a library. Thanks anyway!&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Using pointer to action/method</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/4187717df3/?limit=250#27bb" rel="alternate"/><published>2022-03-03T13:23:57.879000Z</published><updated>2022-03-03T13:23:57.879000Z</updated><author><name>h-hermsen</name><uri>https://forge.codesys.com/u/hermsen/</uri></author><id>https://forge.codesys.combaf446b7a71358ee83c3634e5147a488cadf6ced</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;1) "You can't pass a method or an action like that." &lt;br/&gt;
=&amp;gt; Obviously, but Interfaces are very neat and flexible and hold the key to solve this "problem". I simply explained what the basic mechanism of an interface is, rather then explain the correct usage in this specific case to solve the issue. I don't think that the  user gains anything from Copy/Paste solutions if he/she does not understand the basics. &lt;/p&gt;
&lt;p&gt;2) "Please inform yourself!" &lt;br/&gt;
=&amp;gt; A remark on which I will not comment 🙊&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Using pointer to action/method</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/4187717df3/?limit=50#6d90/54b5/3758" rel="alternate"/><published>2022-03-03T12:25:49.122000Z</published><updated>2022-03-03T12:25:49.122000Z</updated><author><name>ludecus</name><uri>https://forge.codesys.com/u/ludecus/</uri></author><id>https://forge.codesys.comf85451352b7fb2894bd1da54ebdd5aa8c9208a15</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Whoho! If i get you right, it's still Object-oriented programming. Please inform yourself!&lt;/p&gt;
&lt;p&gt;You can't pass a method or an action like that.&lt;/p&gt;
&lt;p&gt;If the second fb owns the first fb, it will look like that:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;FUNCTION_BLOCK&lt;/span&gt; &lt;span class="n"&gt;SecondFB&lt;/span&gt;
&lt;span class="n"&gt;VAR&lt;/span&gt;
    &lt;span class="n"&gt;firstFb&lt;/span&gt;     &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;FirstFb&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;instance&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;child&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt;
&lt;span class="n"&gt;END_VAR&lt;/span&gt;

&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="k"&gt;call&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="k"&gt;method&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;child&lt;/span&gt;
&lt;span class="n"&gt;firstFb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SomethingCallable&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;If the second fb doesn't know the first fb, you will need an interface.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;FUNCTION_BLOCK&lt;/span&gt; &lt;span class="n"&gt;FirstFb&lt;/span&gt; &lt;span class="n"&gt;IMPLEMENTS&lt;/span&gt; &lt;span class="n"&gt;I_FirstFb&lt;/span&gt;

&lt;span class="n"&gt;FUNCTION_BLOCK&lt;/span&gt; &lt;span class="n"&gt;SecondFB&lt;/span&gt;
&lt;span class="n"&gt;VAR_INPUT&lt;/span&gt;
    &lt;span class="n"&gt;ifirstFb&lt;/span&gt;    &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;I_FirstFb&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="n"&gt;reference&lt;/span&gt; &lt;span class="k"&gt;to&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="k"&gt;first&lt;/span&gt; &lt;span class="n"&gt;fb&lt;/span&gt;
&lt;span class="n"&gt;END_VAR&lt;/span&gt;

&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="k"&gt;call&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="k"&gt;method&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;reference&lt;/span&gt;
&lt;span class="n"&gt;ifirstFb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SomethingCallable&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</summary></entry><entry><title>Using pointer to action/method</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/4187717df3/?limit=250#6d90/54b5/4040" rel="alternate"/><published>2022-03-03T11:49:38.527000Z</published><updated>2022-03-03T11:49:38.527000Z</updated><author><name>h-hermsen</name><uri>https://forge.codesys.com/u/hermsen/</uri></author><id>https://forge.codesys.com4b2e070f76b9f021067885682742a75dc196a675</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Interfaces are the way to go. Read up on it. It helps you do the following:&lt;/p&gt;
&lt;p&gt;You can access any FB Instance's methods/properties, (BUT NO ACTIONS!) directly.&lt;/p&gt;
&lt;p&gt;See Pseudo code below for a simple  explanation (NO declarations provided!)&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;VAR&lt;/span&gt;
    &lt;span class="n"&gt;FB1&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;fbSomeFB&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="n"&gt;Implements&lt;/span&gt; &lt;span class="n"&gt;I_InterfaceExample&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;FB2&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;fbSomeFB&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="n"&gt;Implements&lt;/span&gt; &lt;span class="n"&gt;I_InterfaceExample&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;xSwitch&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;BOOL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;I_Example&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;I_InterfaceExample&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;FB1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="n"&gt;we&lt;/span&gt; &lt;span class="n"&gt;staticly&lt;/span&gt; &lt;span class="n"&gt;couple&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;interface&lt;/span&gt; &lt;span class="k"&gt;to&lt;/span&gt; &lt;span class="n"&gt;FB1&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;declaration&lt;/span&gt;

&lt;span class="n"&gt;END_VAR&lt;/span&gt;

&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="n"&gt;BODY&lt;/span&gt; &lt;span class="n"&gt;CODE&lt;/span&gt;

&lt;span class="n"&gt;FB1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;MethodX&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="k"&gt;Equals&lt;/span&gt; &lt;span class="n"&gt;FB1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;MethodX&lt;/span&gt; &lt;span class="n"&gt;but&lt;/span&gt; &lt;span class="k"&gt;after&lt;/span&gt; &lt;span class="n"&gt;xSwitch&lt;/span&gt; &lt;span class="n"&gt;points&lt;/span&gt; &lt;span class="k"&gt;to&lt;/span&gt; &lt;span class="n"&gt;FB2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;MethodX&lt;/span&gt;
&lt;span class="n"&gt;I_Example&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;MethodX&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="k"&gt;IF&lt;/span&gt; &lt;span class="n"&gt;xSwitch&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt;
   &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="n"&gt;Now&lt;/span&gt; &lt;span class="n"&gt;we&lt;/span&gt; &lt;span class="n"&gt;dynamicly&lt;/span&gt; &lt;span class="n"&gt;switch&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;Interface&lt;/span&gt; &lt;span class="k"&gt;to&lt;/span&gt; &lt;span class="n"&gt;FB2&lt;/span&gt;
   &lt;span class="n"&gt;I_Example&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;FB2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="n"&gt;Please&lt;/span&gt; &lt;span class="n"&gt;use&lt;/span&gt; &lt;span class="n"&gt;__QueryInterface&lt;/span&gt; &lt;span class="n"&gt;here&lt;/span&gt; &lt;span class="n"&gt;since&lt;/span&gt; &lt;span class="n"&gt;I&lt;/span&gt; &lt;span class="n"&gt;skipped&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;simplicity&lt;/span&gt; &lt;span class="n"&gt;sake&lt;/span&gt;
   &lt;span class="n"&gt;xSwitch&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;FALSE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;END_IF&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</summary></entry></feed>