<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Computed Property &#8211; Xojo Programming Blog</title>
	<atom:link href="https://blog.xojo.com/tag/computed-property/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.xojo.com</link>
	<description>Blog about the Xojo programming language and IDE</description>
	<lastBuildDate>Tue, 02 Mar 2021 17:26:29 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>A Lazy Computed Property</title>
		<link>https://blog.xojo.com/2020/01/27/a-lazy-computed-property/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Mon, 27 Jan 2020 10:00:00 +0000</pubDate>
				<category><![CDATA[Learning]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Computed Property]]></category>
		<category><![CDATA[Lazy Loading]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=6468</guid>

					<description><![CDATA[Have a class that has an object property that needs to be initialized or instantiated? You can always instantiate the property in the Constructor (or Open event) like this:]]></description>
										<content:encoded><![CDATA[
<p>Do you have a class that has an object property that needs to be initialized or instantiated? You can always instantiate the property in the Constructor (or Open event) like this:</p>



<pre class="wp-block-preformatted">MyClass1 = New MyClass</pre>



<p>But you can also do this using a Computed Property on a Class (I&#8217;m using TestClass for this example).</p>



<p>First, create a private property such as <strong>mMyClass1 As MyClass</strong>. It will be Nil by default as all object properties are.</p>



<p>Then create a Computed Property called <strong>MyClass1 As MyClass</strong>.</p>



<p>In the Get, check if mMyClass1 is Nil. If it is, create it. Then return it.</p>



<pre class="wp-block-preformatted">If mMyClass1 Is Nil Then<br>   mMyClass1 = New MyClass<br>End If<br>Return mMyClass1</pre>



<p>Most likely you’d want this property to be read-only so you would not implement Set (even though the property is read-only, since it is an object you&#8217;ll still be able to modify the properties it contains). But if you did want a way for the object reference to be changed, you can do this in the Set:</p>



<pre class="wp-block-preformatted">mMyClass1 = value</pre>



<p>Now you can make use of MyClass1 on TestClass as shown below. The above technique has two advantages over instantiating the property in the Constructor:</p>



<ol class="wp-block-list"><li>It keeps the code more closely associated with the property.</li><li>The property is only initialized when it is first accessed.</li></ol>



<pre class="wp-block-preformatted">Var tc As New TestClass
tc.MyClass1.TestNumProperty = 42</pre>



<p>This technique is also referred to as <a href="https://en.wikipedia.org/wiki/Lazy_loading">Lazy Loading</a> or Lazy Initialization.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Computed Property Tips for Debugging</title>
		<link>https://blog.xojo.com/2019/05/20/computed-property-tips-for-debugging/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Mon, 20 May 2019 17:39:33 +0000</pubDate>
				<category><![CDATA[Learning]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Computed Property]]></category>
		<category><![CDATA[Debugging]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=5756</guid>

					<description><![CDATA[Here are a couple tips you can use with computed properties that are helpful when debugging.]]></description>
										<content:encoded><![CDATA[
<p>Here are a couple tips you can use with computed properties.</p>



<span id="more-5756"></span>



<h2 class="wp-block-heading">Read-Only Computed Properties</h2>



<p>When you create a Computed Property, you&#8217;ll get a section call Get and a section called Set. The Get section is where you put the code to return the value for the property and the Set section is where you put code to set the computed property value. Did you know you do not have to fill in both sections?</p>



<p>If you leave the Set section empty, you&#8217;ve created a read-only computed property. You&#8217;ll be able to get its value as per usual but if you try to set a value you&#8217;ll get a compile error. This can sometimes be a great alternative to using a method because the computed property value appears in the debugger.</p>



<figure class="wp-block-image"><img fetchpriority="high" decoding="async" width="1024" height="300" src="https://blog.xojo.com/wp-content/uploads/2019/05/2019-05-20_10-21-01-1-1024x300.png" alt="" class="wp-image-5757" srcset="https://blog.xojo.com/wp-content/uploads/2019/05/2019-05-20_10-21-01-1-1024x300.png 1024w, https://blog.xojo.com/wp-content/uploads/2019/05/2019-05-20_10-21-01-1-300x88.png 300w, https://blog.xojo.com/wp-content/uploads/2019/05/2019-05-20_10-21-01-1-768x225.png 768w, https://blog.xojo.com/wp-content/uploads/2019/05/2019-05-20_10-21-01-1.png 1072w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>The sections with code are shown in bold so you can tell a read-only property because only its Set section will be bold.</p>



<h2 class="wp-block-heading">Break on Usage</h2>



<p>When debugging you may have situations where you would find it helpful to know when one of your property values changes. You can do this by changing a regular property to a Computed Property. To do this, right-click on the property and choose &#8220;Convert to Computed Property&#8221;. You&#8217;ll now have two related properties: a private &#8220;backing&#8221; property with a prefix of &#8220;m&#8221; (for example mLastName As String) and a corresponding Computed Property with the original name (for example LastName) that uses the private property to get and set its value.</p>



<p>In the Get and Set sections you can now set breakpoints on the code there so you&#8217;ll drop into the Debugger any time the property is accessed or changed.</p>



<figure class="wp-block-image"><img decoding="async" width="1024" height="335" src="https://blog.xojo.com/wp-content/uploads/2019/05/2019-05-20_10-22-55-1024x335.png" alt="" class="wp-image-5759" srcset="https://blog.xojo.com/wp-content/uploads/2019/05/2019-05-20_10-22-55-1024x335.png 1024w, https://blog.xojo.com/wp-content/uploads/2019/05/2019-05-20_10-22-55-300x98.png 300w, https://blog.xojo.com/wp-content/uploads/2019/05/2019-05-20_10-22-55-768x251.png 768w, https://blog.xojo.com/wp-content/uploads/2019/05/2019-05-20_10-22-55.png 1064w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>More Debugger and Computed Property tips are here:</p>



<ul class="wp-block-list"><li><a href="https://documentation.xojo.com/getting_started/debugging/debugger_usage.html">User Guide: Debugger</a></li><li><a href="https://documentation.xojo.com/getting_started/using_the_xojo_language/properties.html#Computed_Property">User Guide: Computed Properties</a></li><li><a href="https://www.xojo.com/store/#conference">XDC 2018 Session: Avoiding Troubleshooting Troubles</a></li></ul>



<p></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
