<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Property that returns REFERENCE TO Interface type?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/ed8e767878/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/ed8e767878/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/ed8e767878/</id><updated>2021-11-23T18:55:48.778000Z</updated><subtitle>Recent posts to Property that returns REFERENCE TO Interface type?</subtitle><entry><title>Property that returns REFERENCE TO Interface type?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/ed8e767878/?limit=25#8f92/8877/181e/924d" rel="alternate"/><published>2021-11-23T18:55:48.778000Z</published><updated>2021-11-23T18:55:48.778000Z</updated><author><name>thecolonel26</name><uri>https://forge.codesys.com/u/thecolonel26/</uri></author><id>https://forge.codesys.comee992e0b134042d6a4af2d500ac73fb225a3f569</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Thank you very much. I think that is what I needed to know. I did not know that interfaces were passed by reference only. Knowing that now everything makes more sense.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Property that returns REFERENCE TO Interface type?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/ed8e767878/?limit=25#8f92/8877/181e" rel="alternate"/><published>2021-11-20T06:40:48.874000Z</published><updated>2021-11-20T06:40:48.874000Z</updated><author><name>i-campbell</name><uri>https://forge.codesys.com/u/i-campbell/</uri></author><id>https://forge.codesys.com1babbffd82e0953b60f15077a264d65ce21d33ae</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;an interface contains methods and properties.&lt;br/&gt;
an instance of an interface, contains only a pointer. The compiler uses this pointer to know where to access the methods and pointers of the interface - which can only be, as you know, some function block which implements it.&lt;/p&gt;
&lt;p&gt;A reference again contains only a pointer. The compiler treats it differently though, and when you use the := operator, it copies the right hand side to the object behind the reference.&lt;/p&gt;
&lt;p&gt;So if you have a reference to interface.. it is like a double pointer.  Your Reference tells you where in memory you can find a variable of type interface. This interface then tells you, where in memory you can find an instance of a function block.&lt;/p&gt;
&lt;p&gt;So you see, because you seem to only want one level of pointing, it would be sufficient for your property to return an IEngineeringValue, and use the := to assign it to another IEngineeringValue.&lt;/p&gt;
&lt;p&gt;The code you have in your opening post fails because... nowhere is there a variable of type IEngineeringValue, with which you can reference.&lt;/p&gt;
&lt;p&gt;tl;dr&lt;br/&gt;
Reference, Interface and Pointer are all essentially the same thing, they store a memory location of some object.  The difference is in the semantics of how you access the object, and how you update the memory location.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Property that returns REFERENCE TO Interface type?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/ed8e767878/?limit=25#9c26/2ba8" rel="alternate"/><published>2021-11-20T02:49:52.521000Z</published><updated>2021-11-20T02:49:52.521000Z</updated><author><name>thecolonel26</name><uri>https://forge.codesys.com/u/thecolonel26/</uri></author><id>https://forge.codesys.com5174f3528a342801bfaf9527bf35238f41db137b</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I think you are incorrectly assuming what IEngneeringValue contains.&lt;/p&gt;
&lt;p&gt;Right now it has it's own Properties of Value and MeaUnitAsString. &lt;/p&gt;
&lt;p&gt;The intend is to have a mechanism in place so that different types of engineering values can be compared if they are of the same type, Like Temperature, could be compared if if one instance is of using Celsius and one instance using Fahrenheit etc.&lt;/p&gt;
&lt;p&gt;Further set points in the system will be stored in the same mechanism. &lt;/p&gt;
&lt;p&gt;So I have a very valid reason for want to but a complex type behind an interface early on.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Property that returns REFERENCE TO Interface type?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/ed8e767878/?limit=25#8f92/8877" rel="alternate"/><published>2021-11-20T02:41:08.866000Z</published><updated>2021-11-20T02:41:08.866000Z</updated><author><name>thecolonel26</name><uri>https://forge.codesys.com/u/thecolonel26/</uri></author><id>https://forge.codesys.come79738a67e9eb25fc2a0e11cdf8b20394e5b5aa8</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Trying to return a Reference to EngValueBase but using type IEngineeringValue so that the consumer doesn't care what the base class is. I plan to have different implementations of the EngValue later on which is why I want it to be behind an interface.&lt;/p&gt;
&lt;p&gt;I have tried using := instead of Ref= but I get a run time exception, of access violation.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Property that returns REFERENCE TO Interface type?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/ed8e767878/?limit=250#9c26" rel="alternate"/><published>2021-11-18T23:54:43.763000Z</published><updated>2021-11-18T23:54:43.763000Z</updated><author><name>h-hermsen</name><uri>https://forge.codesys.com/u/hermsen/</uri></author><id>https://forge.codesys.come09aec70587c026db170052ed13a5f2caf599ef6</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;actually, to me the whole pointer and the interface do not make sense, since a&lt;br/&gt;
property can be regarded as a value, but this interface with only some engineering value do not make any sense at all.&lt;/p&gt;
&lt;p&gt;Maybe the folloing  will help you understand my point better.&lt;/p&gt;
&lt;p&gt;An analog IO point could be reflected via some STRUCT like so.&lt;br/&gt;
Such a struct is the output of an FB that scales an analog input or output channel;&lt;/p&gt;
&lt;p&gt;Analog.Raw ( unscaled IO input value)&lt;br/&gt;
Analog.Value ( scaled between rangemin and max in eng unit)&lt;br/&gt;
Analog.RangeMin&lt;br/&gt;
Analog.RangeMax&lt;br/&gt;
Analog.Unit ( engineering units of analog measurement )&lt;br/&gt;
Analog.ChStatus ( contains the channel status )&lt;br/&gt;
Analog.ValPerc ( scaled value between 0..100 % instead of eng units )&lt;br/&gt;
Analog.Decimals (contains the prefered decimals when presenting this value)&lt;br/&gt;
Analog.Forced ( by setting True we can force a user value instead of the channel value&lt;br/&gt;
Analog.ForcedValue ( this value will overrule the IO value if forced is True)&lt;/p&gt;
&lt;p&gt;If I want to share this IO point struct, I could make this whole struct as a single get / set or some methods in an Interface, not just a single member out of the struct as a value in the interface.&lt;/p&gt;
&lt;p&gt;I hope you understand my point,&lt;/p&gt;
&lt;p&gt;good luck and have fun! &lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Property that returns REFERENCE TO Interface type?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/ed8e767878/?limit=50#8f92" rel="alternate"/><published>2021-11-18T22:47:45.433000Z</published><updated>2021-11-18T22:47:45.433000Z</updated><author><name>tvm</name><uri>https://forge.codesys.com/u/tvm/</uri></author><id>https://forge.codesys.com578460a7e72648713c47241f42ed9bd6bd04e7c3</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I'm not clear on exactly what you're trying to do here, but creating a reference to the interface is not necessary.  Just make your property of type IEngineeringValue, and in your property do &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c"&gt;LiveValue:= _liveValue&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;the interface acts kind of a like a reference already&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Property that returns REFERENCE TO Interface type?</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/ed8e767878/?limit=25#cb9f" rel="alternate"/><published>2021-11-18T19:07:24.080000Z</published><updated>2021-11-18T19:07:24.080000Z</updated><author><name>thecolonel26</name><uri>https://forge.codesys.com/u/thecolonel26/</uri></author><id>https://forge.codesys.com375bf200432a5a63eaae14a698e697535844a1f8</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I have a property&lt;br/&gt;
defined as &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt;PROPERTY PUBLIC LiveValue : REFERENCE TO IEngineeringValue&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;I have a VAR _liveValue : EngValueBase (Which Implements IEngineeringValue)&lt;/p&gt;
&lt;p&gt;I defined the Get for LiveValue as&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt;LiveValue REF= _liveValue;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;But I get the following build error&lt;br/&gt;
C0032: Cannot convert type 'REFERENCE TO IEngineeringValue' to type'EngValueBase'&lt;/p&gt;
&lt;p&gt;Which seems like it is backwards and should say &lt;br/&gt;
Cannot convert type 'EngValueBase' to type  'REFERENCE TO IEngineeringValue'&lt;/p&gt;
&lt;p&gt;but regardless &lt;strong&gt;what is going wrong here&lt;/strong&gt;?&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>