<?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>OOP &#8211; Xojo Programming Blog</title>
	<atom:link href="https://blog.xojo.com/tag/oop/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, 04 Mar 2025 12:52:13 +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>Understanding Interfaces in Object-Oriented Programming with Xojo</title>
		<link>https://blog.xojo.com/2025/01/15/understanding-interfaces-in-object-oriented-programming-with-xojo/</link>
		
		<dc:creator><![CDATA[Gabriel Ludosanu]]></dc:creator>
		<pubDate>Wed, 15 Jan 2025 14:00:00 +0000</pubDate>
				<category><![CDATA[Learning]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Interfaces]]></category>
		<category><![CDATA[Object-Oriented]]></category>
		<category><![CDATA[OOP]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=14294</guid>

					<description><![CDATA[If you are learning Object-Oriented Programming (OOP) or are curious about software development, you have probably heard the term Interfaces. This article explains the concept of&#8230;]]></description>
										<content:encoded><![CDATA[
<p>If you are learning Object-Oriented Programming (OOP) or are curious about software development, you have probably heard the term <a href="https://documentation.xojo.com/getting_started/object-oriented_programming/interfaces.html" data-type="link" data-id="https://documentation.xojo.com/getting_started/object-oriented_programming/interfaces.html" target="_blank" rel="noreferrer noopener">Interfaces</a>. This article explains the concept of Interfaces in OOP, how they work, and provides two code examples.</p>



<h2 class="wp-block-heading" id="what-is-an-interface"><strong>What is an Interface?</strong></h2>



<p>An Interface in Object-Oriented Programming acts as a contract or a blueprint. It defines a set of methods (functions) that a class must implement, but it does not provide the actual implementation of those methods. Think of it as a list of rules or requirements that a class agrees to follow. This approach makes your code more flexible, reusable, and easier to maintain.</p>



<p>For example, imagine you are building a game with different types of characters, such as warriors, wizards, and archers. Each character might have an attack method, but the way they attack is different. An Interface ensures that all characters have an attack method, but each class can implement it in its own unique way.</p>



<h2 class="wp-block-heading" id="why-use-interfaces"><strong>Why Use Interfaces?</strong></h2>



<ol class="wp-block-list">
<li><strong>Flexibility</strong>: Interfaces allow different classes to be used interchangeably if they implement the same Interface. This makes your code adaptable and scalable.</li>



<li><strong>Reusability</strong>: You can write code that works with any class that implements the Interface, promoting code reuse.</li>



<li><strong>Consistency</strong>: Interfaces enforce consistency across classes, ensuring they all have the required methods.</li>



<li><strong>Polymorphism</strong>: Interfaces enable polymorphism, allowing you to handle different objects through the same interface.</li>
</ol>



<h2 class="wp-block-heading" id="how-to-use-interfaces-in-xojo"><strong>How to Use Interfaces in Xojo</strong></h2>



<p>In Xojo, you can create and implement Interfaces to define a set of methods that multiple classes can share, even if they do not share a common superclass. Follow these steps to use Interfaces in Xojo:</p>



<ol class="wp-block-list">
<li><strong>Create an Interface</strong>: Go to the Insert menu in the Xojo IDE and select Class Interface. Give the Interface a descriptive name.</li>
</ol>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="349" height="200" src="https://blog.xojo.com/wp-content/uploads/2025/01/image-2.png" alt="" class="wp-image-14351" srcset="https://blog.xojo.com/wp-content/uploads/2025/01/image-2.png 349w, https://blog.xojo.com/wp-content/uploads/2025/01/image-2-300x172.png 300w" sizes="(max-width: 349px) 100vw, 349px" /></figure>



<ol class="wp-block-list">
<li><strong>Define Methods</strong>: Add methods to the Interface. These methods have no code; they only define the method names and parameters.</li>
</ol>



<figure class="wp-block-image size-full"><img decoding="async" width="260" height="59" src="https://blog.xojo.com/wp-content/uploads/2025/01/image-3.png" alt="" class="wp-image-14352"/></figure>



<ol class="wp-block-list">
<li><strong>Implement the Interface in a Class</strong>: For a class to use the Interface, select the class and from the Inspector, press the Choose button and mark the newly created Interface.</li>
</ol>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<figure class="wp-block-image size-full"><img decoding="async" width="297" height="140" src="https://blog.xojo.com/wp-content/uploads/2025/01/image-4.png" alt="" class="wp-image-14353"/></figure>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="741" height="532" src="https://blog.xojo.com/wp-content/uploads/2025/01/image-5.png" alt="" class="wp-image-14354" srcset="https://blog.xojo.com/wp-content/uploads/2025/01/image-5.png 741w, https://blog.xojo.com/wp-content/uploads/2025/01/image-5-300x215.png 300w" sizes="auto, (max-width: 741px) 100vw, 741px" /></figure>
</div>
</div>



<h2 class="wp-block-heading" id="example-1-beginner-friendly-interface"><strong>Example 1: Beginner-Friendly Interface</strong></h2>



<p>Let’s start with a simple example. Create an Interface called&nbsp;<code>IAnimal</code>&nbsp;that defines a&nbsp;<code>Speak</code>&nbsp;method. Then, create two classes,&nbsp;<code>Dog</code>&nbsp;and&nbsp;<code>Cat</code>, that implement this Interface.</p>



<h3 class="wp-block-heading" id="step-by-step-guide"><strong>Step-by-Step Guide</strong></h3>



<ol class="wp-block-list">
<li><strong>Define the Interface</strong>
<ul class="wp-block-list">
<li>From the Insert menu, select Class Interface, name it&nbsp;<code>IAnimal</code>&nbsp;and then create a new method&nbsp;<code>Speak</code>.</li>
</ul>
</li>



<li><strong>Create the Dog Class</strong>
<ul class="wp-block-list">
<li>Create a class named&nbsp;<code>Dog</code>&nbsp;(Insert menu &gt; Class) and from the Inspector, make sure to select the Interface. Xojo will automatically add the&nbsp;<code>Speak</code>&nbsp;method to the class so let’s add some code:<code>MessageBox("Woof!")</code></li>
</ul>
</li>



<li><strong>Create the Cat Class</strong>
<ul class="wp-block-list">
<li>Create another class, named&nbsp;<code>Cat</code>&nbsp;(Insert menu &gt; Class) and add the following code to the&nbsp;<code>Speak</code>&nbsp;method:<code>MessageBox("Meow!")</code></li>
</ul>
</li>



<li><strong>Test the Interface</strong></li>
</ol>



<p>Add the following code, to test the Interface, either in the&nbsp;<code>Pressed</code>&nbsp;event of a DesktopButton, or to the&nbsp;<code>Opening</code>&nbsp;event of a DesktopWindow:</p>



<pre class="wp-block-code"><code>Var animals() As IAnimal
animals.Add(New Dog)
animals.Add(New Cat)

For Each animal As IAnimal In animals
  animal.Speak()
Next</code></pre>



<h2 class="wp-block-heading" id="example-2-advanced-interface-with-parameters"><strong>Example 2: Interface with Parameters</strong></h2>



<p>Now, create a new Class Interface called&nbsp;<code>ICalculator</code>&nbsp;that defines a&nbsp;<code>Calculate</code>&nbsp;method. This method takes two numbers as parameters and returns a result. Then, create two classes,&nbsp;<code>Adder</code>&nbsp;and&nbsp;<code>Multiplier</code>, that implement this Interface.</p>



<h3 class="wp-block-heading" id="step-by-step-guide-1"><strong>Step-by-Step Guide</strong></h3>



<ol class="wp-block-list">
<li><strong>Define the Interface</strong>
<ul class="wp-block-list">
<li>Add the following method to define the Interface:<code> Public Function Calculate(a As Integer, b As Integer) As Integer</code></li>
</ul>
</li>



<li><strong>Create the Adder Class</strong>
<ul class="wp-block-list">
<li>Add the following code to the<code>Calculate</code>&nbsp;function:<code> Return a + b</code></li>
</ul>
</li>



<li><strong>Create the Multiplier Class</strong>
<ul class="wp-block-list">
<li>Add the following code to the<code>Calculate</code>&nbsp;function:<code> Return a * b</code></li>
</ul>
</li>



<li><strong>Test the Interface</strong></li>
</ol>



<pre class="wp-block-code"><code>  Var calculators() As ICalculator
  calculators.Add(New Adder)
  calculators.Add(New Multiplier)

  For Each calc As ICalculator In calculators
    MessageBox("Result: " + calc.Calculate(7, 2).ToString)
  Next</code></pre>



<h2 class="wp-block-heading" id="practical-use-cases-for-interfaces">Some <strong>Practical Use Cases for Interfaces</strong></h2>



<p>Interfaces are versatile and can be used in many situations to make your code more modular and easier to maintain. Here are some practical use cases for Interfaces in Object-Oriented Programming:</p>



<h3 class="wp-block-heading" id="data-access-abstraction"><strong>1. Data Access Abstraction</strong></h3>



<p>Abstract data access using Interfaces. For example, define an&nbsp;IDatabase&nbsp;Interface with methods&nbsp;Connect,&nbsp;Query, and&nbsp;Disconnect. Classes that implement this Interface can interact with different database systems (like MySQL, PostgreSQL, SQLite), allowing you to switch databases without changing your core code.</p>



<h3 class="wp-block-heading" id="cross-platform-development"><strong>2. Cross-Platform Development</strong></h3>



<p>Abstract platform-specific functionality using Interfaces. For instance, define an&nbsp;IFileSystem&nbsp;Interface with methods&nbsp;ReadFile&nbsp;and&nbsp;WriteFile. Implement this Interface differently for Windows, macOS, and Linux. Your main code can remain the same across platforms.</p>



<h3 class="wp-block-heading" id="polymorphism"><strong>3. Polymorphism</strong></h3>



<p>Enable polymorphism with Interfaces. This lets you process objects differently based on their actual class, but through the same Interface. This is useful when you want to write code that works with any class that implements a particular Interface.</p>



<h2 class="wp-block-heading" id="key-takeaways"><strong>Key Takeaways</strong></h2>



<ul class="wp-block-list">
<li><strong>Interfaces define a set of methods</strong>&nbsp;that classes must implement.</li>



<li>They make your code&nbsp;<strong>flexible, reusable, and easier to understand</strong>.</li>



<li>Interfaces enforce&nbsp;<strong>consistency</strong>&nbsp;across different classes.</li>



<li>They enable&nbsp;<strong>polymorphic behavior</strong>, allowing you to write generic code.</li>
</ul>



<h2 class="wp-block-heading" id="conclusion"><strong>Conclusion</strong></h2>



<p>Whether you&#8217;re building a simple application or a complex system, interfaces are a powerful tool in your Object-Oriented Programming toolkit, and Xojo makes them incredibly easy to use. They promote better code organization, flexibility, and reusability. Start experimenting with Interfaces in your projects, and you will see how they can improve your code!</p>



<p>Additional info on Interfaces: <a href="https://documentation.xojo.com/getting_started/object-oriented_programming/interfaces.html" target="_blank" rel="noreferrer noopener">https://documentation.xojo.com/getting_started/object-oriented_programming/interfaces.html</a></p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p>If you have questions or want to share your own Interface examples, feel free to start a forum discussion. Happy coding! <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f680.png" alt="🚀" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<p><em>Gabriel is a digital marketing enthusiast who loves coding with Xojo to create cool software tools for any platform. He is always eager to learn and share new ideas!</em></p>



<ul class="wp-block-social-links has-normal-icon-size is-content-justification-center is-layout-flex wp-container-core-social-links-is-layout-16018d1d wp-block-social-links-is-layout-flex"><li class="wp-social-link wp-social-link-facebook  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.facebook.com/goxojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M12 2C6.5 2 2 6.5 2 12c0 5 3.7 9.1 8.4 9.9v-7H7.9V12h2.5V9.8c0-2.5 1.5-3.9 3.8-3.9 1.1 0 2.2.2 2.2.2v2.5h-1.3c-1.2 0-1.6.8-1.6 1.6V12h2.8l-.4 2.9h-2.3v7C18.3 21.1 22 17 22 12c0-5.5-4.5-10-10-10z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Facebook</span></a></li>

<li class="wp-social-link wp-social-link-x  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://x.com/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M13.982 10.622 20.54 3h-1.554l-5.693 6.618L8.745 3H3.5l6.876 10.007L3.5 21h1.554l6.012-6.989L15.868 21h5.245l-7.131-10.378Zm-2.128 2.474-.697-.997-5.543-7.93H8l4.474 6.4.697.996 5.815 8.318h-2.387l-4.745-6.787Z" /></svg><span class="wp-block-social-link-label screen-reader-text">X</span></a></li>

<li class="wp-social-link wp-social-link-linkedin  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.linkedin.com/company/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19.7,3H4.3C3.582,3,3,3.582,3,4.3v15.4C3,20.418,3.582,21,4.3,21h15.4c0.718,0,1.3-0.582,1.3-1.3V4.3 C21,3.582,20.418,3,19.7,3z M8.339,18.338H5.667v-8.59h2.672V18.338z M7.004,8.574c-0.857,0-1.549-0.694-1.549-1.548 c0-0.855,0.691-1.548,1.549-1.548c0.854,0,1.547,0.694,1.547,1.548C8.551,7.881,7.858,8.574,7.004,8.574z M18.339,18.338h-2.669 v-4.177c0-0.996-0.017-2.278-1.387-2.278c-1.389,0-1.601,1.086-1.601,2.206v4.249h-2.667v-8.59h2.559v1.174h0.037 c0.356-0.675,1.227-1.387,2.526-1.387c2.703,0,3.203,1.779,3.203,4.092V18.338z"></path></svg><span class="wp-block-social-link-label screen-reader-text">LinkedIn</span></a></li>

<li class="wp-social-link wp-social-link-github  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://github.com/topics/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M12,2C6.477,2,2,6.477,2,12c0,4.419,2.865,8.166,6.839,9.489c0.5,0.09,0.682-0.218,0.682-0.484 c0-0.236-0.009-0.866-0.014-1.699c-2.782,0.602-3.369-1.34-3.369-1.34c-0.455-1.157-1.11-1.465-1.11-1.465 c-0.909-0.62,0.069-0.608,0.069-0.608c1.004,0.071,1.532,1.03,1.532,1.03c0.891,1.529,2.341,1.089,2.91,0.833 c0.091-0.647,0.349-1.086,0.635-1.337c-2.22-0.251-4.555-1.111-4.555-4.943c0-1.091,0.39-1.984,1.03-2.682 C6.546,8.54,6.202,7.524,6.746,6.148c0,0,0.84-0.269,2.75,1.025C10.295,6.95,11.15,6.84,12,6.836 c0.85,0.004,1.705,0.114,2.504,0.336c1.909-1.294,2.748-1.025,2.748-1.025c0.546,1.376,0.202,2.394,0.1,2.646 c0.64,0.699,1.026,1.591,1.026,2.682c0,3.841-2.337,4.687-4.565,4.935c0.359,0.307,0.679,0.917,0.679,1.852 c0,1.335-0.012,2.415-0.012,2.741c0,0.269,0.18,0.579,0.688,0.481C19.138,20.161,22,16.416,22,12C22,6.477,17.523,2,12,2z"></path></svg><span class="wp-block-social-link-label screen-reader-text">GitHub</span></a></li>

<li class="wp-social-link wp-social-link-youtube  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.youtube.com/c/XojoInc" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M21.8,8.001c0,0-0.195-1.378-0.795-1.985c-0.76-0.797-1.613-0.801-2.004-0.847c-2.799-0.202-6.997-0.202-6.997-0.202 h-0.009c0,0-4.198,0-6.997,0.202C4.608,5.216,3.756,5.22,2.995,6.016C2.395,6.623,2.2,8.001,2.2,8.001S2,9.62,2,11.238v1.517 c0,1.618,0.2,3.237,0.2,3.237s0.195,1.378,0.795,1.985c0.761,0.797,1.76,0.771,2.205,0.855c1.6,0.153,6.8,0.201,6.8,0.201 s4.203-0.006,7.001-0.209c0.391-0.047,1.243-0.051,2.004-0.847c0.6-0.607,0.795-1.985,0.795-1.985s0.2-1.618,0.2-3.237v-1.517 C22,9.62,21.8,8.001,21.8,8.001z M9.935,14.594l-0.001-5.62l5.404,2.82L9.935,14.594z"></path></svg><span class="wp-block-social-link-label screen-reader-text">YouTube</span></a></li></ul>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Avoiding Memory Leaks with WeakRef</title>
		<link>https://blog.xojo.com/2024/05/07/avoiding-memory-leaks-with-weakref/</link>
		
		<dc:creator><![CDATA[Javier Menendez]]></dc:creator>
		<pubDate>Tue, 07 May 2024 16:11:00 +0000</pubDate>
				<category><![CDATA[Cross-Platform]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Cast]]></category>
		<category><![CDATA[Memory]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[WeakRef]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=12861</guid>

					<description><![CDATA[Is not that common of an issue, but it happens - when searching for memory leaks, remember to check any cross-referenced objects. Cross-referenced objects are, well, just that, objects that need to reference each other. For example, when "ClassA" needs to know about "ClassB", and "ClassB" needs to know about "ClassA". Continue reading to see how this can cause memory leaks in your projects and how to use Xojo's WeakRef to fix it.]]></description>
										<content:encoded><![CDATA[
<p>This is not that common of an issue, but&nbsp;it happens &#8211; when searching for memory leaks, remember to check any cross-referenced objects. Cross-referenced objects are, well, just that, objects that need to reference each other. For example, when &#8220;ClassA&#8221; needs to know about &#8220;ClassB&#8221;, and &#8220;ClassB&#8221; needs to know about &#8220;ClassA&#8221;. Continue reading to see how this can cause memory leaks in your projects and how to use Xojo&#8217;s WeakRef to fix it.</p>



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



<p>If you&#8217;re dealing with a situation in your code where two classes need to reference each other, then you could be leaking memory if you haven&#8217;t taken steps to prevent that.</p>



<p>Let&#8217;s look at this with a simple example.</p>



<ul class="wp-block-list">
<li>Create a new Xojo project and add two new classes to it, ClassA and ClassB.</li>



<li>Add a ClassBReference As ClassB property to ClassA.</li>



<li>Add a ClassAReference As ClassA property to ClassB.</li>



<li>Add a Constructor to ClassB using the following signature:</li>
</ul>



<pre id="xojo" class="wp-block-code"><code>Constructor(reference As ClassA)</code></pre>



<p>And add this line of code to the method:</p>



<pre id="xojo" class="wp-block-code"><code>Me.ClassAReference = reference</code></pre>



<p>Next, add the Destructor method to both classes and type &#8220;Break&#8221; as the only line of code for them. This will allow us to see if they leak memory or not. For example, if when debugging the example project the Debugger doesn&#8217;t reach the Break lines, that would mean that the Destructor has not been called and, thus, the objects are not released from memory. They are leaking!</p>



<ul class="wp-block-list">
<li>Now add the Opening event handler to Window1 and type these lines into it:</li>
</ul>



<pre id="xojo" class="wp-block-code"><code>CreateReferences
Break</code></pre>



<p>As you can see, it calls the CreateReferences method and then breaks into the debugger.</p>



<ul class="wp-block-list">
<li>Now add the CreateReferences method to Window1 and type these lines of code in the associated Code Editor:</li>
</ul>



<pre id="xojo" class="wp-block-code"><code>Var ca As New ClassA
Var cb As New ClassB(ca)

ca.ClassBReference = cb</code></pre>



<p>Now it&#8217;s clear what is going on here: ClassB instance is keeping a &#8220;hard&#8221; reference to ClassA (via the ca instance), and then the ca reference is keeping a &#8220;hard&#8221; reference to the classB instance cb.</p>



<p>Run the project. Is the debugger stopping in the Break lines of ClassA and ClassB Destructors? Nope. They are leaking because they are using hard cross-references with each other.</p>



<p>You can see it more clearly when accessing Global &gt; Runtime &gt; Contents in the Debugger panel. Both objects are still alive:</p>


<div class="wp-block-image is-style-default">
<figure class="aligncenter"><img loading="lazy" decoding="async" width="1250" height="132" src="https://blog.xojo.com/wp-content/uploads/2024/04/Screenshot-2024-04-03-at-12.14.16.png" alt="" class="wp-image-12862" srcset="https://blog.xojo.com/wp-content/uploads/2024/04/Screenshot-2024-04-03-at-12.14.16.png 1250w, https://blog.xojo.com/wp-content/uploads/2024/04/Screenshot-2024-04-03-at-12.14.16-300x32.png 300w, https://blog.xojo.com/wp-content/uploads/2024/04/Screenshot-2024-04-03-at-12.14.16-1024x108.png 1024w, https://blog.xojo.com/wp-content/uploads/2024/04/Screenshot-2024-04-03-at-12.14.16-768x81.png 768w" sizes="auto, (max-width: 1250px) 100vw, 1250px" /></figure>
</div>


<h3 class="wp-block-heading">WeakRef to the Rescue!</h3>



<p>But let&#8217;s say that your app design needs to keep these references. How do we solve this situation? The answer is using <a href="https://en.wikipedia.org/wiki/Weak_reference">weak references</a> instead of hard references, and the Xojo language has a class for it: <a href="https://documentation.xojo.com/api/language/weakref.html#weakref">WeakRef</a>.</p>



<p>Let&#8217;s change ClassA and ClassB properties so their type is a WeakRef. Setting their definition as:</p>



<pre id="xojo" class="wp-block-code"><code>ClassBReference As WeakRef
ClassAReference As WeakRef</code></pre>



<p>And let&#8217;s change the ClassB Constructor code so it creates a new WeakRef instance from the received object, instead of assigning it directly to the property.</p>



<pre id="xojo" class="wp-block-code"><code>ClassAReference = New WeakRef(reference)</code></pre>



<p>And let&#8217;s change the code in the CreateReferences method to:</p>



<pre id="xojo" class="wp-block-code"><code>Var ca As New ClassA<br>Var cb As New Classb(ca)<br><br>ca.ClassBReference = New WeakRef(cb)</code></pre>



<p>Run the example project again. Now you will see that the Debugger stops at the &#8220;Break&#8221; lines for each Class Destructor. Which means they are correctly released from memory. Problem solved!</p>



<h3 class="wp-block-heading">WeakRef Memory Care</h3>



<p>When using WeakRef objects through the code, keep in mind that accessing the real object they are referencing is done through the WeakRef.Value property in addition to <a href="https://documentation.xojo.com/getting_started/object-oriented_programming/advanced_oop_features.html#getting-started-object-oriented-programming-advanced-oop-features-casting">Cast</a> to the original Class.</p>



<p>To see it more clearly, add the &#8220;SayHello&#8221; method to ClassB and type this line of code into the associated code editor:</p>



<pre id="xojo" class="wp-block-code"><code>MessageBox("Hi From ClassB Instance")</code></pre>



<p>Then, select the CreateReferences method from Window1 and add the following line of code at the end:</p>



<pre id="xojo" class="wp-block-code"><code>ClassB(ca.ClassBReference.Value).SayHello</code></pre>



<p>First, we are accessing the ClassBRefence property from the ca instance; that gives us access to the WeakRef instance property, so we need to access its Value property in order to get access to the real object instance we are really interested (a ClassB instance).</p>



<p>But, because the Value property returns a generic Object, we need to Cast it to the class instance we expect (and should know) that is referenced by the Value property; in this case a &#8220;ClassB&#8221; instance. To do this, we are using the Cast expression:</p>



<pre id="xojo" class="wp-block-code"><code>ClassB(ca.ClassBReference.Value)</code></pre>



<p>Next, and because we did Cast it to ClassB, we can continue using the dot notation in order to call any of the methods / properties exposed by ClassB, in this case the &#8220;SayHello&#8221; method.</p>



<p>Run the app again and now the ClassB instance referenced by the ClassA instance is displaying the MessageBox.</p>



<p>In addition, when accessing a hard referenced object in your class properties it can be good to do a sanity check like:</p>



<pre id="xojo" class="wp-block-code"><code>If ca.ClassBReference &lt;&gt; Nil Then
  ca.ClassBReference.SayHello
End If</code></pre>



<p>But when using WeakRefs you need to do a double check. First against the WeakRef itself, because it can be a Nil object! And second, against the object referenced by the WeakRef itself. So the previous check will read now:</p>



<pre id="xojo" class="wp-block-code"><code>If ca.ClassBReference &lt;&gt; Nil And ca.ClassBReference.Value &lt;&gt; Nil then<br>  ClassB(ClassBReference.Value).SayHello<br>End If</code></pre>



<h3 class="wp-block-heading">Clearing It!</h3>



<p>All in all, cross-referencing objects among class instances is probably not the best design, but sometimes it is needed. In case your app design needs to follow such a path, take care and use weak references (with Xojo&#8217;s WeakRef class) instead of hard references.</p>



<p>Keep it in memory (or not, if it is leaking)… and happy coding with Xojo!</p>



<p><em>Javier Menendez is an engineer at Xojo and has been using Xojo since 1998. He lives in Castellón</em>, <em>Spain and hosts regular Xojo hangouts en español. Ask Javier questions on Twitter at <a href="https://twitter.com/xojoes" target="_blank" rel="noreferrer noopener">@XojoES</a> or on the <a href="https://forum.xojo.com/u/javier_menendez/summary" target="_blank" rel="noreferrer noopener">Xojo Forum</a>.</em></p>



<ul class="wp-block-social-links has-normal-icon-size is-content-justification-center is-layout-flex wp-container-core-social-links-is-layout-16018d1d wp-block-social-links-is-layout-flex"><li class="wp-social-link wp-social-link-facebook  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.facebook.com/goxojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M12 2C6.5 2 2 6.5 2 12c0 5 3.7 9.1 8.4 9.9v-7H7.9V12h2.5V9.8c0-2.5 1.5-3.9 3.8-3.9 1.1 0 2.2.2 2.2.2v2.5h-1.3c-1.2 0-1.6.8-1.6 1.6V12h2.8l-.4 2.9h-2.3v7C18.3 21.1 22 17 22 12c0-5.5-4.5-10-10-10z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Facebook</span></a></li>

<li class="wp-social-link wp-social-link-x  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://x.com/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M13.982 10.622 20.54 3h-1.554l-5.693 6.618L8.745 3H3.5l6.876 10.007L3.5 21h1.554l6.012-6.989L15.868 21h5.245l-7.131-10.378Zm-2.128 2.474-.697-.997-5.543-7.93H8l4.474 6.4.697.996 5.815 8.318h-2.387l-4.745-6.787Z" /></svg><span class="wp-block-social-link-label screen-reader-text">X</span></a></li>

<li class="wp-social-link wp-social-link-linkedin  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.linkedin.com/company/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19.7,3H4.3C3.582,3,3,3.582,3,4.3v15.4C3,20.418,3.582,21,4.3,21h15.4c0.718,0,1.3-0.582,1.3-1.3V4.3 C21,3.582,20.418,3,19.7,3z M8.339,18.338H5.667v-8.59h2.672V18.338z M7.004,8.574c-0.857,0-1.549-0.694-1.549-1.548 c0-0.855,0.691-1.548,1.549-1.548c0.854,0,1.547,0.694,1.547,1.548C8.551,7.881,7.858,8.574,7.004,8.574z M18.339,18.338h-2.669 v-4.177c0-0.996-0.017-2.278-1.387-2.278c-1.389,0-1.601,1.086-1.601,2.206v4.249h-2.667v-8.59h2.559v1.174h0.037 c0.356-0.675,1.227-1.387,2.526-1.387c2.703,0,3.203,1.779,3.203,4.092V18.338z"></path></svg><span class="wp-block-social-link-label screen-reader-text">LinkedIn</span></a></li>

<li class="wp-social-link wp-social-link-github  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://github.com/topics/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M12,2C6.477,2,2,6.477,2,12c0,4.419,2.865,8.166,6.839,9.489c0.5,0.09,0.682-0.218,0.682-0.484 c0-0.236-0.009-0.866-0.014-1.699c-2.782,0.602-3.369-1.34-3.369-1.34c-0.455-1.157-1.11-1.465-1.11-1.465 c-0.909-0.62,0.069-0.608,0.069-0.608c1.004,0.071,1.532,1.03,1.532,1.03c0.891,1.529,2.341,1.089,2.91,0.833 c0.091-0.647,0.349-1.086,0.635-1.337c-2.22-0.251-4.555-1.111-4.555-4.943c0-1.091,0.39-1.984,1.03-2.682 C6.546,8.54,6.202,7.524,6.746,6.148c0,0,0.84-0.269,2.75,1.025C10.295,6.95,11.15,6.84,12,6.836 c0.85,0.004,1.705,0.114,2.504,0.336c1.909-1.294,2.748-1.025,2.748-1.025c0.546,1.376,0.202,2.394,0.1,2.646 c0.64,0.699,1.026,1.591,1.026,2.682c0,3.841-2.337,4.687-4.565,4.935c0.359,0.307,0.679,0.917,0.679,1.852 c0,1.335-0.012,2.415-0.012,2.741c0,0.269,0.18,0.579,0.688,0.481C19.138,20.161,22,16.416,22,12C22,6.477,17.523,2,12,2z"></path></svg><span class="wp-block-social-link-label screen-reader-text">GitHub</span></a></li>

<li class="wp-social-link wp-social-link-youtube  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.youtube.com/c/XojoInc" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M21.8,8.001c0,0-0.195-1.378-0.795-1.985c-0.76-0.797-1.613-0.801-2.004-0.847c-2.799-0.202-6.997-0.202-6.997-0.202 h-0.009c0,0-4.198,0-6.997,0.202C4.608,5.216,3.756,5.22,2.995,6.016C2.395,6.623,2.2,8.001,2.2,8.001S2,9.62,2,11.238v1.517 c0,1.618,0.2,3.237,0.2,3.237s0.195,1.378,0.795,1.985c0.761,0.797,1.76,0.771,2.205,0.855c1.6,0.153,6.8,0.201,6.8,0.201 s4.203-0.006,7.001-0.209c0.391-0.047,1.243-0.051,2.004-0.847c0.6-0.607,0.795-1.985,0.795-1.985s0.2-1.618,0.2-3.237v-1.517 C22,9.62,21.8,8.001,21.8,8.001z M9.935,14.594l-0.001-5.62l5.404,2.82L9.935,14.594z"></path></svg><span class="wp-block-social-link-label screen-reader-text">YouTube</span></a></li></ul>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>The One Person Framework for the Rest of Us</title>
		<link>https://blog.xojo.com/2024/05/02/the-one-person-framework-for-the-rest-of-us/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Thu, 02 May 2024 14:00:00 +0000</pubDate>
				<category><![CDATA[Cross-Platform]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Xojo Cloud]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Development Tools]]></category>
		<category><![CDATA[Enterprise Software]]></category>
		<category><![CDATA[Multi-Platform Development]]></category>
		<category><![CDATA[Object-Oriented]]></category>
		<category><![CDATA[One-Person Framework]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Rapid Application Development]]></category>
		<category><![CDATA[Small Business]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=12882</guid>

					<description><![CDATA[The technology and development world is always changing. First released in 1998, Xojo&#8217;s longevity is a testament to its ability and willingness to adapt from&#8230;]]></description>
										<content:encoded><![CDATA[
<p>The technology and development world is always changing. First released in 1998, Xojo&#8217;s longevity is a testament to its ability and willingness to adapt from the early days of desktop apps, to web apps and on to mobile apps.</p>



<p>Throughout that time, software development has generally become more difficult with developers having to learn a wide variety of tools and programming languages, many of which are the hot thing for a short while and then disappear afterwards for the next hot new thing as the cycle repeats.</p>



<p>Up until recently this was not as big a deal for tech companies because they could just hire their way out of the problem. Teams got big and bloated, often because the tools being used were large, complex, rapidly changing and difficult to learn. So the solution, in opposition of the <a href="https://en.wikipedia.org/wiki/The_Mythical_Man-Month">Mythical Man Month</a>, was to throw more people at it. This was feasible because of 0% interest rates and the relative ease of raising capital.</p>



<figure class="wp-block-image"><a href="https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4c4ae90-9d8d-4b2a-8301-2ee4be611df7_1152x640.jpeg" target="_blank" rel="noreferrer noopener"><img decoding="async" src="https://substackcdn.com/image/fetch/w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4c4ae90-9d8d-4b2a-8301-2ee4be611df7_1152x640.jpeg" alt=""/></a></figure>



<p>But that era is over. Interest rates are no longer historically low and raising capital for companies is now much harder and less desirable than it once was. This means technology companies are reducing staff and hiring more judiciously. Fewer people now have to do more with less.</p>



<p>The idea of a “one person framework” is that there should be a way for a single developer to create software using just one development framework. This is not a new idea, but it is being talked about again because of these recent changes with how technology companies work. In many ways, Xojo is the original one person framework. From its inception, with inspiration from Visual Basic, Xojo let you make complete apps more efficiently without having to also learn other tools, languages or frameworks.</p>



<p>So what can Xojo, as a one person framework, do for you? Xojo lets you build most of the apps your company is likely to need, using only Xojo itself and its easy-to learn object-oriented programming language (which is similar to Visual Basic and Python, languages that many people already are familiar with). Xojo is a cross-platform, integrated development environment (IDE) that combines an object-oriented programming language, visual designer, code editor, debugger and more into one tool and one framework.</p>



<p>With Xojo you can make apps for most of the commonly used platforms that your business is likely to need.</p>



<p><strong>Desktop Apps</strong></p>



<p>Xojo has been a great way to make desktop apps since its inception in 1998. Unlike Java, Electron or other frameworks you’ve seen throughout the years, Xojo makes native apps and can do so for the major desktop platforms: Windows, macOS and Linux. Yes, that includes native ARM and x86 apps as well.</p>



<p>With a single project, you can click one button to have Xojo build separate native apps for each of those platforms. To further drive that point home, the Xojo IDE itself is a desktop app made with Xojo that runs on Windows, macOS and Linux.</p>



<p>With Xojo you have access to many commonly-used controls and the Xojo framework with support for databases, JSON, XML, RegEx, Zip/Unzip, networking and so much more.</p>



<p><strong>Web Apps</strong></p>



<p>Since 2010, Xojo has been able to make web apps. Xojo uses a somewhat unique approach to web apps by running compiled code on the web server. This code communicates to the app running on the web browser using an internal JavaScript framework and Bootstrap for the UI, which you don’t really need to worry about. It’s all handled automatically.</p>



<p>This approach is great for business purposes as it lets you make web apps using a development pattern that is very similar to what is used to make desktop apps.</p>



<p>If you don&#8217;t want to deal with the hassle of managing your own web app server, Xojo even offers Xojo Cloud as a fully managed web hosting service with 1-click deployment of your Xojo web apps.</p>



<p><strong>Mobile Apps</strong></p>



<p>Mobile support first appeared for iOS in 2013 and Android support was recently added in 2023. Using Xojo to make native mobile apps that can be deployed in their respective app stores is yet another way Xojo can help one person make more apps.</p>



<p>A developer that already knows how to use Xojo can jump right into mobile development without having to learn yet another IDE and programming language.</p>



<p><strong>Console Apps</strong></p>



<p>Console apps are text apps that run from the command line. These app are great for automating internal processes or other command-line tools. You can even build Console apps that communicate with other console apps to build a chain of tools for processing or converting data, for example.</p>



<h4 class="wp-block-heading">Xojo Framework</h4>



<p>A single person can create all of the above types of apps because Xojo uses the same programming language for all of them. And as mentioned above, the Xojo framework has many built-in features and is broadly compatible across all the different project types. There are differences, of course, but we strive for consistency and compatibility.</p>



<p>For just a few of its many capabilities, all platforms have the same framework classes and methods for things such as Dictionary, Set, URLConnection, files, SQLite, and most graphics. And speaking of examples, Xojo includes over 400 example projects from which to learn.</p>



<figure class="wp-block-image is-resized"><a href="https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62cdb62a-4fe8-4d7a-ac61-cf301408c2dc_1152x640.jpeg" target="_blank" rel="noreferrer noopener"><img decoding="async" src="https://substackcdn.com/image/fetch/w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62cdb62a-4fe8-4d7a-ac61-cf301408c2dc_1152x640.jpeg" alt="" style="width:915px;height:auto"/></a></figure>



<h2 class="wp-block-heading">Could Xojo Work For You?</h2>



<p>As you should now realize, a single developer using Xojo could reasonably create a desktop app (for Windows, macOS and Linux), a web app, and mobile apps for iOS and Android. If you previously had multiple teams of multiple people creating that many apps, then Xojo could really save you a lot of money and time.</p>



<p>Will you use Xojo to make the next Photoshop, FaceBook, Excel or Google Docs clone? Perhaps not, but most companies don&#8217;t create those types of apps. Xojo does a lot, but it does not and cannot do everything. There is a limit to what any single framework can do, otherwise it becomes too large for its own good, collapsing under its own weight.</p>



<p>Instead, most businesses have much different needs and often require specially created software. For business apps, especially bespoke small-business apps, Xojo can often be an ideal solution by allowing apps to be created faster, more easily and at less cost than can be done with other tools. This saves you money and time, both of which are in short supply these days.</p>



<p><a href="https://www.xojo.com/download/">Xojo is free</a> for learning, development and testing! Give it a spin to see what it can do for you.</p>



<p><em>Paul learned to program in BASIC at age 13 and has programmed in more languages than he remembers, with Xojo being an obvious favorite. When not working on Xojo, you can find him talking about retrocomputing at <a href="https://goto10.substack.com" target="_blank" rel="noreferrer noopener">Goto 10</a> and </em>on Mastodon @lefebvre@hachyderm.io.</p>



<ul class="wp-block-social-links has-normal-icon-size is-content-justification-center is-layout-flex wp-container-core-social-links-is-layout-16018d1d wp-block-social-links-is-layout-flex"><li class="wp-social-link wp-social-link-facebook  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.facebook.com/goxojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M12 2C6.5 2 2 6.5 2 12c0 5 3.7 9.1 8.4 9.9v-7H7.9V12h2.5V9.8c0-2.5 1.5-3.9 3.8-3.9 1.1 0 2.2.2 2.2.2v2.5h-1.3c-1.2 0-1.6.8-1.6 1.6V12h2.8l-.4 2.9h-2.3v7C18.3 21.1 22 17 22 12c0-5.5-4.5-10-10-10z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Facebook</span></a></li>

<li class="wp-social-link wp-social-link-x  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://x.com/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M13.982 10.622 20.54 3h-1.554l-5.693 6.618L8.745 3H3.5l6.876 10.007L3.5 21h1.554l6.012-6.989L15.868 21h5.245l-7.131-10.378Zm-2.128 2.474-.697-.997-5.543-7.93H8l4.474 6.4.697.996 5.815 8.318h-2.387l-4.745-6.787Z" /></svg><span class="wp-block-social-link-label screen-reader-text">X</span></a></li>

<li class="wp-social-link wp-social-link-linkedin  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.linkedin.com/company/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19.7,3H4.3C3.582,3,3,3.582,3,4.3v15.4C3,20.418,3.582,21,4.3,21h15.4c0.718,0,1.3-0.582,1.3-1.3V4.3 C21,3.582,20.418,3,19.7,3z M8.339,18.338H5.667v-8.59h2.672V18.338z M7.004,8.574c-0.857,0-1.549-0.694-1.549-1.548 c0-0.855,0.691-1.548,1.549-1.548c0.854,0,1.547,0.694,1.547,1.548C8.551,7.881,7.858,8.574,7.004,8.574z M18.339,18.338h-2.669 v-4.177c0-0.996-0.017-2.278-1.387-2.278c-1.389,0-1.601,1.086-1.601,2.206v4.249h-2.667v-8.59h2.559v1.174h0.037 c0.356-0.675,1.227-1.387,2.526-1.387c2.703,0,3.203,1.779,3.203,4.092V18.338z"></path></svg><span class="wp-block-social-link-label screen-reader-text">LinkedIn</span></a></li>

<li class="wp-social-link wp-social-link-github  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://github.com/topics/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M12,2C6.477,2,2,6.477,2,12c0,4.419,2.865,8.166,6.839,9.489c0.5,0.09,0.682-0.218,0.682-0.484 c0-0.236-0.009-0.866-0.014-1.699c-2.782,0.602-3.369-1.34-3.369-1.34c-0.455-1.157-1.11-1.465-1.11-1.465 c-0.909-0.62,0.069-0.608,0.069-0.608c1.004,0.071,1.532,1.03,1.532,1.03c0.891,1.529,2.341,1.089,2.91,0.833 c0.091-0.647,0.349-1.086,0.635-1.337c-2.22-0.251-4.555-1.111-4.555-4.943c0-1.091,0.39-1.984,1.03-2.682 C6.546,8.54,6.202,7.524,6.746,6.148c0,0,0.84-0.269,2.75,1.025C10.295,6.95,11.15,6.84,12,6.836 c0.85,0.004,1.705,0.114,2.504,0.336c1.909-1.294,2.748-1.025,2.748-1.025c0.546,1.376,0.202,2.394,0.1,2.646 c0.64,0.699,1.026,1.591,1.026,2.682c0,3.841-2.337,4.687-4.565,4.935c0.359,0.307,0.679,0.917,0.679,1.852 c0,1.335-0.012,2.415-0.012,2.741c0,0.269,0.18,0.579,0.688,0.481C19.138,20.161,22,16.416,22,12C22,6.477,17.523,2,12,2z"></path></svg><span class="wp-block-social-link-label screen-reader-text">GitHub</span></a></li>

<li class="wp-social-link wp-social-link-youtube  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.youtube.com/c/XojoInc" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M21.8,8.001c0,0-0.195-1.378-0.795-1.985c-0.76-0.797-1.613-0.801-2.004-0.847c-2.799-0.202-6.997-0.202-6.997-0.202 h-0.009c0,0-4.198,0-6.997,0.202C4.608,5.216,3.756,5.22,2.995,6.016C2.395,6.623,2.2,8.001,2.2,8.001S2,9.62,2,11.238v1.517 c0,1.618,0.2,3.237,0.2,3.237s0.195,1.378,0.795,1.985c0.761,0.797,1.76,0.771,2.205,0.855c1.6,0.153,6.8,0.201,6.8,0.201 s4.203-0.006,7.001-0.209c0.391-0.047,1.243-0.051,2.004-0.847c0.6-0.607,0.795-1.985,0.795-1.985s0.2-1.618,0.2-3.237v-1.517 C22,9.62,21.8,8.001,21.8,8.001z M9.935,14.594l-0.001-5.62l5.404,2.82L9.935,14.594z"></path></svg><span class="wp-block-social-link-label screen-reader-text">YouTube</span></a></li></ul>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Creating your own ComboBox Subclass with Sorted Menu Items</title>
		<link>https://blog.xojo.com/2021/03/25/creating-your-own-combobox-subclass-with-sorted-menu-items/</link>
		
		<dc:creator><![CDATA[Javier Menendez]]></dc:creator>
		<pubDate>Thu, 25 Mar 2021 10:00:00 +0000</pubDate>
				<category><![CDATA[Cross-Platform]]></category>
		<category><![CDATA[Desktop]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[ComboBox]]></category>
		<category><![CDATA[Object-Oriented]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Xojo API 2.0]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=8206</guid>

					<description><![CDATA[The Xojo ComboBox desktop control is a powerful one. It combines the capabilities of a TextField with the PopupMenu. That means that you can choose from the available options in the associated menu or you can type another value in the ComboBox text field. What about getting the ComboBox to do things not included in the class?]]></description>
										<content:encoded><![CDATA[
<p>The Xojo <a href="https://documentation.xojo.com/api/deprecated/combobox.html"><strong>ComboBox</strong></a> desktop control is a powerful one. It combines the capabilities of a <a href="https://documentation.xojo.com/api/deprecated/textfield.html"><strong>TextField</strong></a> with the <a href="https://documentation.xojo.com/api/deprecated/popupmenu.html"><strong>PopupMenu</strong></a>. That means that you can choose any of the available options from the associated menu (for example those assigned using the <strong>Appearance &gt; Initial value</strong> option in the Inspector Panel) or simply type another value in the ComboBox text field.</p>



<p>What about getting the ComboBox to do things not included in the class? In this tutorial you will learn how to add the text typed by the user as an option in the associated ComboBox menu. We&#8217;ll make sure entries are not duplicated and that they are sorted alphabetically. We&#8217;ll use the <code>AddAllRows</code> method to add a strings array to those already available in the ComboBox menu. In addition, we will add a new method to the ComboBox so you can retrieve all the menu entries as an Array of Strings.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="505" class="wp-image-8212 aligncenter" src="https://blog.xojo.com/wp-content/uploads/2021/03/SortedComboBox-1024x505.png" alt="" srcset="https://blog.xojo.com/wp-content/uploads/2021/03/SortedComboBox-1024x505.png 1024w, https://blog.xojo.com/wp-content/uploads/2021/03/SortedComboBox-300x148.png 300w, https://blog.xojo.com/wp-content/uploads/2021/03/SortedComboBox-768x378.png 768w, https://blog.xojo.com/wp-content/uploads/2021/03/SortedComboBox-1536x757.png 1536w, https://blog.xojo.com/wp-content/uploads/2021/03/SortedComboBox.png 1648w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>


<p>You&#8217;ll find it very convenient that Xojo is an&nbsp;Object-Oriented Programming language as you create any subclass from any existing one. Creating your own specialized subclasses adds tons of extra functionality to <em>any</em> of your projects since they can be used in your other desktop projects. Keep reading to create your own subclasses! <a href="https://bit.ly/2OS99hO">Download this Xojo project</a></p>
<h2>1. Adding a Class to the Project</h2>
<p>Start a new Xojo Desktop project and select the <strong>Insert &gt; class</strong> option from the menu in order to add a new class to the Navigator.</p>
<p>With the new <code>Class1</code> item selected in the Navigator, change the following values in the associated Inspector Panel:</p>
<ul>
<li><strong>Name:</strong> MyComboBox (you may use any other class name you want).</li>
<li><strong>Super:</strong> ComboBox</li>
</ul>
<p>Confirm the changes.&nbsp;You&#8217;ll see how the new class item is now named&nbsp;<code>MyComboBox</code> in the Navigator, while its icon has changed to the one for the ComboBox control.</p>
<h2>2. Adding Event Handlers to the Class</h2>
<p>Keep <code>MyComboBox</code> selected in the Navigator and then select the <strong>Insert &gt; Event Handler</strong> option from the menu. That action will open a new window listing all the available Event Handlers for the ComboBox class and, thus, also for all the subclasses created from it &#8211; like our new class.</p>
<p>Select the <code>Change</code>, <code>KeyDown</code>, <code>Open</code> and <code>LostFocus</code> entries from the list and confirm the changes by clicking on the &#8220;OK&#8221; button. The &#8220;Add Event Handler&#8221; window will close and the selected entries will be added to the <code>MyComboBox</code> item in the Navigator.</p>
<p>Use the <code>KeyDown</code> and <code>LostFocus</code> event handlers to add the text typed by the user as new entries in the ComboBox menu.</p>
<p>Select the <code>KeyDown</code> event under the <code>MyComboBox</code> item in the Navigator and type the following code in the associated Code Editor:</p>
<pre>AddNewEntry(key)
Return RaiseEvent KeyDown(Key)</pre>
<p>The <code>AddNewEntry</code> method will add the new entry to our ComboBox menu.&nbsp;Notice the <code>RaiseEvent KeyDown(Key)</code> line of code. Because our subclass makes use of this event handler, that means that it will not be available to any instances (objects) created from the class, as for example those created when adding the class to a Window in the Layout Editor.</p>
<h2>3. Adding Event Definitions</h2>
<p>With <code>MyComboBox</code> still selected in the Navigator, choose the <strong>Insert &gt; Event Definition</strong> menu option and add the following values in the associated Inspector Panel:</p>
<ul>
<li><strong>Event Name:</strong> KeyDown</li>
<li><strong>Parameters:</strong> Key As String</li>
<li><strong>Return Type:</strong> Boolean</li>
</ul>
<p>This creates the same Event Handler for the class so it can be implemented by any of the instances created from the class, while the <code>RaiseEvent KeyDown(Key)</code> line of code will make sure that this event will also be called for its instances.</p>
<p>Now select the <code>LostFocus</code> event handler from the <code>MyComboBox</code> item in the Navigator and type the following code in the associated Code Editor:</p>
<pre>Me.AddRow(Me.Text)
RaiseEvent LostFocus</pre>
<p>Once again, because we are implementing this event handler, we need to make it available for our class instances. With <code>MyComboBox</code> selected, choose the <strong>Insert &gt; Event Definition</strong> menu option adding the following value in the associated Inspector Panel:</p>
<ul>
<li><strong>Event Name:</strong> LostFocus</li>
</ul>
<p>Now select the <code>Open</code> event handler under <code>MyComboBox</code>, typing the following code in the associated Code Editor:</p>
<pre>Var selectedIndex As Integer = Me.mSelectedRowIndex

Var s() As String = Me.Rows
s.Sort
Me.RemoveAllRows
Me.AddAllRows(s)

If selectedIndex = -1 Then
  Me.mSelectedRowIndex = -1
  Me.Text = ""
End If

RaiseEvent Open</pre>
<p>Once again, we need to create a new Event Definition for the class using the values:</p>
<ul>
<li><strong>Event Name:</strong> Open</li>
</ul>
<p>And repeat the last operation to add the last Event Definition with the following:</p>
<ul>
<li><strong>Event Name:</strong> Change</li>
</ul>
<p>Type this snippet of code in the associated Code Editor for the <code>Change</code> Event Handler:</p>
<pre>Var s() As String = Me.rows
Var n As Integer = s.LastRowIndex

For i As Integer = 0 To n
  If s(i) = Me.Text Then
    Me.mSelectedRowIndex = i
    Exit For
  End If
Next

RaiseEvent Change</pre>
<h2>4. Adding Methods to the Class</h2>
<p>While <code>MyComboBox</code> is still selected in the Navigator, select the <strong>Insert &gt; Method</strong> option from the menu, using the following values in the associated Inspector Panel:</p>
<ul>
<li><strong>Method Name:</strong> AddNewEntry</li>
<li><strong>Parameters:</strong> Key As String</li>
<li><strong>Scope:</strong> Protected</li>
</ul>
<p>And type the following snippet of code in the Code Editor associated with the new method:</p>
<pre>// If return key or tab key is pressed then we add the current text to the menu options

If (key.Asc = 13 Or key.Asc = 9) And Me.Text &lt;&gt; "" Then

  Me.AddRow(Me.Text)

End If</pre>
<p>Now add a second method to the class, using the following values:</p>
<ul>
<li><strong>Method Name:</strong> Rows</li>
<li><strong>Return Type:</strong> String()</li>
<li><strong>Scope:</strong> Public</li>
</ul>
<p>And type the following code in the method&#8217;s Code Editor:</p>
<pre>Var r() As String
Var i As Integer = Me.RowCount - 1

For n As Integer = 0 To i
  r.Add(Me.RowValueAt(n))
Next

Return r</pre>
<h2>&nbsp;</h2>
<h2>5. Overriding existing Methods</h2>
<p>You always want your ComboBox menu items to be sorted alphabetically. And that means taking care of the default functionality of the <code>AddRow</code> and <code>AddAllRows</code> methods. At the same time, we don&#8217;t want the <code>AddRowAt</code> ComboBox method to be available for our subclass (it wouldn&#8217;t make much sense to add a new entry at a particular spot in the menu if it wouldn&#8217;t stay at that position afterwards).</p>
<p>Add a couple of new methods to <code>MyComboBox</code> using the following values:</p>
<ul>
<li><strong>Method Name:</strong> AddAllRows</li>
<li><strong>Parameters:</strong> Items() As String</li>
<li><strong>Scope:</strong> Public</li>
</ul>
<ul>
<li><strong>Method Name:</strong> AddRow</li>
<li><strong>Parameters:</strong> Item As String</li>
<li><strong>Scope:</strong> Public</li>
</ul>
<p>Select the <code>AddAllRows</code> method and type the following code in the associated Code Editor:</p>
<pre>Var selectedItem As String = Me.SelectedRow
Var lastAddedItem As String = items(items.LastIndex).Trim.Titlecase

Var d As New Dictionary

Var s() As String = Me.Rows

For n As Integer = 0 To s.LastIndex

  d.Value(s(n)) = Me.RowTagAt(n)

Next

For Each item As String In items
  If Not d.HasKey(item) And item &lt;&gt; "" Then s.Add(item.Trim.Titlecase)
Next

s.Sort
Me.RemoveAllRows

// Calling the overridden superclass method.
Super.AddAllRows(s)

For n As Integer = 0 To s.LastIndex

  If d.HasKey(s(n)) Then
    Me.RowTagAt(n) = d.Value(s(n))
  End If

  If s(n) = selectedItem Then
    Me.mSelectedRowIndex = n
  End If

  If s(n) = lastAddedItem Then
    Me.mLastAddedRowIndex = n
  End If

Next</pre>
<p>Select next the <code>AddRow</code> method and type the following code in the associated Code Editor:</p>
<pre>If item = "" Then Return

item = item.Trim.Titlecase

If Not Me.HasMember(item) Then

  Var selectedItem As String = Me.SelectedRow

  Var d As New Dictionary

  Var s() As String = Me.rows

  For n As Integer = 0 To s.LastIndex

    d.Value(s(n)) = Me.RowTagAt(n)

  Next

  s.Add(item)
  s.Sort

  Me.RemoveAllRows
  Super.AddAllRows(s)

  // Let's restore the original rowtags to their new spot in the menu

  For n As Integer = 0 To s.LastIndex

    If d.HasKey(s(n)) Then
      Me.RowTagAt(n) = d.Value(s(n))
    End If

    If s(n) = selectedItem Then
      Me.mSelectedRowIndex = n
    End If

    If s(n) = item Then
      Me.mLastAddedRowIndex = n
    End If

  Next
End If</pre>
<p>We still need a last method to our class that will check if an item is already among the current entries for the menu. So, add it using the following values:</p>
<ul>
<li><strong>Method Name:</strong> HasMember</li>
<li><strong>Parameters:</strong> Item As String</li>
<li><strong>Return Type:</strong> Boolean</li>
<li><strong>Scope:</strong> Protected</li>
</ul>
<p>Type the following code in the associated Code Editor:</p>
<pre>Var b As Boolean

For Each s As String In Me.Rows
  If s = item Then
    b = True
    Exit For
  End If
Next

Return b</pre>
<h2>&nbsp;</h2>
<h2>6. Overriding Existing Properties</h2>
<p>Because we are sorting the entries in the menu, we also need to make sure that the <code>LastAddedRowIndex</code> and <code>SelectedRowIndex</code> properties are pointing to the right item and selected row index. That means that we need to override the current functionality of the base class.</p>
<p>In order to do that, select the <strong>Insert &gt; Property</strong> option from the menu with the following values in the associated Inspector Panel:</p>
<ul>
<li><strong>Name:</strong> LastAddedRowIndex</li>
<li><strong>Type:</strong> Integer</li>
<li><strong>Scope:</strong> Public</li>
</ul>
<p>With the new property still selected in the <code>MyComboBox</code> class, access the contextual menu and choose the <code>Convert to Computed Property</code> option. That action will add a <code>Get</code> and <code>Set</code> method under the property item, in addition of adding a new <code>mLastAddedRowIndex</code> property whose scope will be Private.</p>
<p>Let&#8217;s add the second Property using these values:</p>
<ul>
<li><strong>Name:</strong> SelectedRowIndex</li>
<li><strong>Type:</strong> Integer</li>
<li><strong>Scope:</strong> Public</li>
</ul>
<p>Once again, with the just added property still selected under the <code>MyComboBox</code> class in the Navigator, select the <code>Convert to Computed Property</code> option from the contextual menu. Then select the <code>Set</code> method under <code>SelectedRowIndex</code> and type the following code in the associated Code Editor:</p>
<pre>Var r() As String = Me.Rows

If value &gt; r.LastIndex Then Raise New OutOfBoundsException

If value &gt; 0 Then
  Me.Text = r(value)
Else
  value = -1
  Me.Text = ""
End If

mSelectedRowIndex = value
RaiseEvent Change</pre>
<p>This is the code that will be executed every time our code sets a new value to the property, so we need to make sure it is between the allowed range, raising a new <code>OutBoundsException</code> exception if it is beyond the limits of the available entries in the menu.</p>
<p>At the same time, if it is not a positive number that would mean that the we don&#8217;t want to select any entry, so we can set the text property of the ComboBox to an empty string and the inner <code>mSelectedRowIndex</code> value to -1.</p>
<h2>7. Putting it to Work</h2>
<p>Now that you have the ComboBox subclass ready to work, choose the <code>Window1</code> item in the Navigator in order to access its Layout Editor. Next, drag the <code>MyComboBox</code> item from the Navigator and drop it over the <code>Window1</code> in the Layout Editor. You can use the layout guides in order to keep it aligned with the window margins.</p>
<p>With the <code>MyCombobox1</code> item still selected in the Layout Editor, access its Panel Inspector in order to assign some initial values for its menu from the <strong>Appearance &gt; Initial Value</strong> section. For our example, you could enter <code>"One"</code>, <code>"Two"</code> and <code>"Three"</code> as the values in the associated editor. And you can&nbsp;also enable the autocomplete option for the control under <strong>Behavior &gt; Allow <a href="https://documentation.xojo.com/api/deprecated/combobox.html#combobox-allowautocomplete">Auto Complete</a></strong>.</p>
<p>Run the example app and observe how every new entry made by the user is added to those already available in the ComboBox menu, while keeping them sorted.</p>
<p>You can add more UI controls to Window1 in order to use the other methods and properties, or just <a href="https://bit.ly/2OS99hO">download the example project</a> and run it from the Xojo IDE. I hope you have found this tutorial helpful and that you can learn from it and adapt it to your needs. If you have questions about this post or the Xojo programming language you can find me at the <a href="https://forum.xojo.com/u/javier_menendez/summary">Xojo Forums</a> and on Twitter <a href="https://twitter.com/xojoes">@xojoES</a>.</p>


<p></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Singletons and the Web</title>
		<link>https://blog.xojo.com/2020/04/28/singletons-and-the-web/</link>
		
		<dc:creator><![CDATA[Wayne Golding]]></dc:creator>
		<pubDate>Tue, 28 Apr 2020 10:00:00 +0000</pubDate>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=6976</guid>

					<description><![CDATA[The singleton design pattern has its place in the desktop environment where there will be only one user running the application, and when that user quits the app the singleton is destroyed. This doesn't fit the requirements of a multi-user environment such as the web where many users will be accessing the application at once. I recently came across this issue when porting a desktop app to the web which required me to design a singleton class that is session sensitive. Here's a walk through of how I achieved my goal. Please note that scopes are particularly important when creating this class.]]></description>
										<content:encoded><![CDATA[
<p>The Singleton design pattern has its place in the desktop environment where there will be only one user running the application, and when that user quits the app the Singleton is destroyed. This doesn&#8217;t fit the requirements of a multi-user environment such as the web where many users will be accessing the application at once. I recently came across this issue when porting a desktop app to the web which required me to design a Singleton class that is session sensitive. Here&#8217;s a walk through of how I achieved my goal. Please note that scopes are particularly important when creating this class.</p>



<p>If you need a refresher on the Singleton design pattern, read <a href="https://blog.xojo.com/2016/06/08/design-patterns-in-xojo-singleton/">Design Patterns in Xojo: Singleton</a>.</p>



<p>First, I inserted a class into my project and called it SessionSingleton (if you don&#8217;t name your class SessionSingleton you need to replace all references to that name in your class).</p>



<p>Next, I added a property to that class with the name SessionIdentifier As String with no default value and set as&nbsp;<strong>private</strong>&nbsp;scope. This will hold the Session.Identifier associated with this object.</p>



<pre class="wp-block-preformatted">Protected Property SessionIdentifier as String</pre>



<p>Now add a method called Constructor and make it&nbsp;<strong>private</strong>, this is to prevent the object from being created outside control of the class.</p>



<pre class="wp-block-preformatted">Private Sub Constructor()

End Sub</pre>



<p>Add another method called Constructor with a parameter SessionIdentifier As String and make it&nbsp;<strong>private</strong>. In this method add the code:</p>



<pre class="wp-block-preformatted">Protected Sub Constructor(SessionIdentifier As String)
  Me.SessionIdentifier = SessionIdentifier
  Constructor()
  
End Sub</pre>



<p>This saves the Session Identifier and runs the constructor method (which may be used by you to initialize properties etc. of the object).</p>



<p>Now, add a shared Property mInstances() As SessionSingleton and make it&nbsp;<strong>private</strong>. This will hold the array of session Singletons.</p>



<pre class="wp-block-preformatted">Private Shared Property mInstances() as SessionSingleton</pre>



<p>Lastly, we need to add two&nbsp;<strong>public</strong>&nbsp;Shared Methods. The first is:</p>



<pre class="wp-block-preformatted">Public Shared Function GetInstance(SessionIdentifier As String) as SessionSingleton
  // Find the instance.  If it exists return it.
  For i As Integer = 0 To mInstances.LastRowIndex
    If mInstances(i).SessionIdentifier = SessionIdentifier Then
      Return mInstances(i)
    End If
  Next
  
  // Not found so create a new instance and return it
  mInstances.AddRow(New SessionSingleton(SessionIdentifier))
  System.DebugLog("Creating new instance for Session with ID " + SessionIdentifier)
  
  Return mInstances(mInstances.LastRowIndex)
  
End Function</pre>



<p>This code returns an existing instance or creates and returns a new one.</p>



<p>Now, because a Web application is multi-user app there&#8217;s the need to clean up when a session is closed so we need the second Shared Method:</p>



<pre class="wp-block-preformatted">Public Shared Sub DestroyInstance(SessionIdentifier As String)
  // This function will remove the instance and should be called from the 
  // Session.Closing event
  For i As Integer = 0 To mInstances.LastRowIndex
    If mInstances(i).SessionIdentifier = SessionIdentifier Then
      mInstances(i) = Nil
      mInstances.RemoveRowAt(i)
    End If
  Next
End Sub</pre>



<p>In this code we find the instance that has the identifier of the current session and destroy that object.</p>



<p>To use the class you would:</p>



<pre class="wp-block-preformatted">Var Singleton As SessionSingleton = SessionSingleton.GetInstance(Session.Identifier)</pre>



<p>Or if in a Session Event Handler:</p>



<pre class="wp-block-preformatted">Var Singleton As SessionSingleton = SessionSingleton.GetInstance(Identifier)</pre>



<p>Add the code to the Session.Closing Event handler to clean up.</p>



<pre class="wp-block-preformatted">SessionSingleton.RemoveInstance(Identifier)</pre>



<p>Don&#8217;t forget to replace all references to SessionSingleton to your class name.</p>



<p>You may have noticed I haven&#8217;t excluded an empty string as the SessionIdentifier and indeed have defaulted the constructor to this empty string. This allows me to use this same class in my desktop projects and potentially when handling Special URL&#8217;s in a web project.</p>



<p><em>Wayne Golding has been a Xojo developer since 2005 and is a Xojo MVP. He operates the IT Company&nbsp;<a href="http://www.axisdirect.nz">Axis Direct Ltd&nbsp;</a>which primarily develops applications using Xojo that integrate with Xero www.xero.com. Wayne’s hobby is robotics where he uses Xojo to build applications for his Raspberry Pi, often implementing IoT for remote control.</em></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>10 Reasons Why You Should Try Xojo</title>
		<link>https://blog.xojo.com/2020/01/21/10-reasons-why-you-should-try-xojo/</link>
		
		<dc:creator><![CDATA[Javier Menendez]]></dc:creator>
		<pubDate>Tue, 21 Jan 2020 15:25:25 +0000</pubDate>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[Cross-Platform]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[XDC]]></category>
		<category><![CDATA[Intro to Xojo Programming Textbook]]></category>
		<category><![CDATA[Multi-Platform Development]]></category>
		<category><![CDATA[Native App Development]]></category>
		<category><![CDATA[Object-Oriented]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[RAD]]></category>
		<category><![CDATA[Rapid Application Development]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=6422</guid>

					<description><![CDATA[With so many programming languages and development environments around … why you should try Xojo? I could tell you more than 400,000 reasons to just jump-in right away; reasons I've heard for over 10 years now from Xojo users around the world that are building all kind of apps, products and solutions in all kinds of fields. Nevertheless, if I really think about, all of these reasons can be condensed into the following 10 main points. Continue reading and I'm pretty sure you will want to give Xojo a try too!]]></description>
										<content:encoded><![CDATA[<p>With so many programming languages and development environments around why should you try Xojo? I could tell you more than 400,000 reasons to just jump-in right away; reasons I&#8217;ve heard for over 10 years now from Xojo users around the world that are building all kind of apps, products and solutions in all kinds of fields. Nevertheless, if I really think about, all of these reasons can be condensed into the following 10 main points. Continue reading and I&#8217;m pretty sure you will want to <a href="http://xojo.com/download/">give Xojo a try</a> too!</p>
<h2>1. Xojo is for everyone</h2>
<p>It doesn&#8217;t matter if you are just starting to <a href="https://www.xojo.com/resources/learn.php">learn how to develop software</a> or if you are already a seasoned developer, Xojo is for everyone! If you are getting your feet wet in coding, then you&#8217;ll find that Xojo offers a programming language that is extremely easy to grasp from the start. In fact, you&#8217;ll find a lot of contextual help in Xojo while coding, and access to the global Help menu is only a click away.</p>
<p>In addition, the <a href="http://documentation.xojo.com">Xojo Documentation</a> website offers really easy-to-follow QuickStarts, Tutorials and Guides letting you make your own Desktop, Web, Android, iOS, Raspberry Pi or Console apps in no time! Add that to the more than 300 video-tutorials you can find in the <a href="http://youtube.com/goxojo">Xojo YouTube channel</a>, and the fact that all the Xojo language documentation is packed with code snippets showing how to implement a particular feature- copy, paste and you are set.</p>
<p>Need some starting points for a better understanding of how Xojo Projects work? The Examples folder included with the <a href="https://xojo.com/download/">Xojo Download</a> includes dozens of complete example projects you can open, run and inspect to see in detail how to implement a particular task or behavior; then you can  adapt and use these for your own projects. Even you can use the Search feature for filtering the example projects by platform, operating system or other criteria.</p>
<p>One thing you&#8217;ll notice the very first time you run Xojo is that you aren&#8217;t inundated with features you don&#8217;t even know what to do with yet! Everything is clear and concise in front of you, hiding the complexity generally associated with the development workflow.</p>
<p>As you advance in your learning process and get more experienced in coding, you can discover more advanced features at your own pace. And even then, things like Web debugging, iOS or Android deployment or truly multi-platform development, are still effortless. Xojo does all of this without installing thousands of files on each operating system or requiring the additional installation of other components in order to properly work.</p>
<p>What if you&#8217;re an experienced developer coming from another development environment or language? Then you&#8217;ll be able to learn and master the Xojo programming language in a blink while watching your productivity increase! In fact, Xojo is an Event-Driven OOP (Object Oriented Programming) language, sharing the same &#8220;dot notation&#8221; syntax used by the most modern programming languages; and Xojo offers guides to port your existing projects, for example, from <a href="http://documentation.xojo.com/topics/migrating_from_other_development_tools/migrating_from_visual_foxpro.html">FoxPro</a> or <a href="http://documentation.xojo.com/UserGuide:Migrating&lt;em&gt;from&lt;/em&gt;Visual&lt;em&gt;Basic">VB6</a> to modern and truly multi-platform deployment with Xojo. And even if you are coming from other development environments as FileMaker or 4D, Xojo makes your solutions available for a more wide range of platforms as native apps and without hidden or extra deployment costs.</p>
<p>Being an OOP language means that Xojo will share the same set of paradigms and/or syntax you are used to dealing with in other programming languages; ranging from PHP to C++, Objective-C, Swift, JavaScript, Python, and others. In fact, you&#8217;ll discover that several of the language keywords, instruction blocks and function or methods calling conventions are very similar to the ones found in those.</p>
<p>Add that to the rich and complete Xojo Framework and the fact that you can even use external libraries if you need to; and you&#8217;ll realize all the possibilities you have at your hands for creating apps and complete solutions that can be used by individuals or companies of all sizes.</p>
<h2>2. Make all kind of apps!</h2>
<p>While several languages and IDEs are more suited or focused on developing a particular kind of products (database driven, mobile, IoT, etc.), with Xojo you&#8217;ll be using the same IDE and programming language to create all of these and more!</p>
<p>For what it is worth, that means that even if you are a self-employed developer, a <a href="https://blog.xojo.com/2015/11/19/the-citizen-developer/">Citizen Developer</a> or need to develop a solution for a company, you&#8217;ll be saving a huge amount of time, money and resources in order to get all these things done with a single development environment. That translates into reduced costs and increased ROI in your development investments; from the simplest ones to the more complex and demanding, including Console apps acting as Daemons, background processes, task helpers… or APIs development as the middleware to interact with both Mobile, Web, Desktop or Raspberry Pi clients!</p>
<p>Do you offer consultancy services or are you working as a freelance developer? With Xojo you&#8217;ll significantly reduce the amount of time you usually spend following multiple changes and evolutions in programming languages, frameworks, SDKs, technologies and, probably, third parties IDEs (among other resources) in order to keep going with your business.</p>
<p>At the same time, due to the fact that Xojo shares the programming language and IDE among all the supported platforms (Desktop, Web, Android, iOS and Raspberry Pi) and architectures (both 32 and 64-bit / Intel and ARM), you can also expand the kind of solutions you can offer to you current or potential clients and keep them running as the technology evolves!</p>
<h2>3. Truly Native, Cross-Compiled, Multi-Platform Apps!</h2>
<p>Some development environments or programming languages are focused (or are more appropriate) to a particular platform or target. With Xojo you&#8217;ll find that all of your apps will be compiled to native binary code on every supported platform.</p>
<p>That means that they will not incur the performance penalties imposed by byte code translations or that they can be easily reverted to source code, even your Web products!</p>
<p>What&#8217;s more important: the compiled apps will look and behave as you expect on every one of the supported operating systems.</p>
<p>In general, all of this means that you can be more confident about the fact that your intellectual property will not be the targeted or exposed by the most common techniques or exploiting attacks; and that translates into additional <em>peace of mind</em> regarding how you protect your investment in developing and deploying your solutions.</p>
<p>Even Xojo is created with Xojo! That is, the IDE offers the same look and feel and set of features from Windows, macOS and Linux.</p>
<h2>4. Do more with less</h2>
<p>During the designing, coding, testing or deployment phases of the product you won&#8217;t need to do complex set-ups or check for ever-changing dependencies! The Xojo IDE abstracts you from all the inherent and underlaying complexity, so you can focus on what really matters: the features that make your product truly unique.</p>
<p>This kind of complexity abstraction is evident not only for Desktop apps, but also for Android and iOS deployments and is especially evident when deploy web apps in combination with <a href="https://www.xojo.com/cloud/">Xojo Cloud.</a></p>
<p>In this last case, you only need to click a button in Xojo to have your web app transferred from the IDE to your Xojo Cloud server. Your app will be up and running in a matter of seconds, without needing to deal with complex server configurations or investing all the required time in being sure that you have all the server security issues covered and under control. Think about that for a moment: if you are a small company or just an independent developer, you don&#8217;t need to invest  extra resources, time and money in order to have your web apps secured and running with confidence.</p>
<p>Of course, if you have the resources and/or the required knowledge, you can deploy your web apps yourself on any VPS or web hosting service of your choice that meets the Xojo Web deployment requirements.</p>
<p>But the best part is that it doesn&#8217;t mind if you&#8217;re developing for Web, Android, iOS, Desktop or Raspberry Pi: you can develop for any of the Xojo supported platforms from the operating system of your choice! In the case of macOS and iOS apps, development can be done on any platform a Mac computer is required for compilation.</p>
<p>In summary: it doesn&#8217;t matter what OS or platform you want or need to code for, you&#8217;ll be using the same IDE and programming language in all the cases, abstracting you from all the particularities and underlaying complexity on every case. And that means doing more in less time!</p>
<h2>5. Rapid Application Development</h2>
<p>It doesn&#8217;t matter if you are creating a Desktop, Web, Android or iOS app; or if you want to build your solutions for Intel or ARM based architectures. With Xojo you will be able to design the user interface via Drag &amp; Drop from a rich set of controls ready to use. It&#8217;s that simple. In fact, the Layout Editor provides visual clues to precisely align every control in the Window, View or Page of the app; and if you&#8217;re targeting for macOS, Web, Android or iOS you&#8217;ll be able to see how your designs react when used in Dark Mode!</p>
<p>Reacting to users&#8217; interactions in your apps is as easy as selecting a user interface control in the Layout Editor, adding the kind of event you&#8217;re interested in from a list (with contextual help about what it does and when it is fired), and writing the code you want to be associated and executed to that particular Event.</p>
<p>Add that to the fact you can reuse your already developed Classes, Modules and other resources; you can even reuse your code between different kinds of projects and targeted platforms!</p>
<h2>6. No chains!</h2>
<p>It doesn&#8217;t matter if the apps or solutions created with Xojo are intended to be used by dozens or thousands of users, even if they are database driven! With Xojo you don&#8217;t have to pay royalties for absolutely anything! Even better: you don&#8217;t need to buy a license in order to try, learn and use Xojo! There is no limited trial, feature limitations or other drawbacks when using the free IDE. Download Xojo and begin learning, developing, running and debugging your projects all without a license.</p>
<p>Features include, the access and use of the supported database engines: from SQLite to MySQL/MariaDB, PostgreSQL, or any other you can access using ODBC, and of course the included features to work with Reports.</p>
<p>You can <a href="https://www.xojo.com/store">buy a Xojo license</a> when you decide that is the time to build your projects. Further, all Xojo licenses are covered by a 90-day money-back guarantee.</p>
<p>In addition, you don&#8217;t even need to pay for what you are not going to use (or going to use right now). What does this mean? Well, let&#8217;s say that if you only work with Windows and only want to create apps for Windows, then you only need to buy the Windows Lite Edition license for that ($99 USD), while if you need your apps to be run from all the supported Desktop platforms (including Raspberry Pi), then the Xojo Desktop Edition license is probably what you&#8217;re looking for ($299 USD); or if you really want to grasp all the Xojo power and target all the Xojo supported platforms (Desktop, iOS, Web and Raspberry Pi), then Xojo Pro is undoubtedly for you ($699 USD)! Oh and Xojo Pi, for building desktop and console apps, <a href="https://xojo.com/redeem/pilicense.php">is free</a>!</p>
<p>You can even upgrade to Xojo Desktop or Pro at any time if you decide that you need to use more advanced features not present in your current edition. In other words, you don&#8217;t need to buy a new license from scratch if you don&#8217;t want to. You can even change your Xojo Cloud plan at any time you require!</p>
<h2>7. You&#8217;re not alone!</h2>
<p>With more than 400,000 users around the world and more than 20 years on the market, the awesome Xojo community is one of the best programming resources you can find around to join to. In the <a href="https://forum.xojo.com">Xojo Forum</a> you&#8217;ll find the largest community and best place to get your questions answered by a large group of enthusiastic and seasoned Xojo developers.</p>
<p>It doesn&#8217;t matter if it&#8217;s a simple or a more complex problem, you&#8217;ll feel welcomed and probably have your problem solved in record time! In fact, many of the replies come from members of the Xojo Staff, ranging from Customer Service to anyone on the Engineering Team or even the Founder and CEO of Xojo himself!</p>
<p>Of course, you have other resources you can (and should!) visit, ranging from a dedicated publication about Xojo development, to Users Groups and Xojo Pages in Facebook, developers blogs about Xojo, and of course the official Xojo channels in Twitter, Instagram or Facebook. Don&#8217;t worry, you don&#8217;t need to search the entire web to find these, we have collected some of these <a href="http://documentation.xojo.com/Resources:Communities,_Social_Media_and_Blogs">valuable resources here</a> and <a href="http://documentation.xojo.com/Resources:Books,_Magazines,_Videos_and_Tutorials">here</a>.</p>
<p>And if you need to get a richer experience and more in-depth knowledge, in a face to face way, then you won&#8217;t want to miss any of the usual <a href="https://www.xojo.com/events/">Xojo Events</a> taking place in several American and European cities each year! There you can chat with other Xojo developers to exchange experiences, attend technical sessions, socialize and create new relationships that can lead in new work projects, etc.</p>
<p>The biggest of these Events is <a href="https://www.xojo.com/xdc/">XDC</a>, with Xojo developers coming in from all around the world, and where you will be able to attend sessions from expert Xojo developers and where you can talk with all the <a href="https://www.xojo.com/company/team.php">Xojo Team</a>!</p>
<h2>8. And you won&#8217;t be left behind</h2>
<p>Did you know that Xojo is still able to open and run projects from earlier releases, even many, many years ago? Sure that in more complex projects you will need to <em>upgrade</em> code, and that&#8217;s because Xojo has evolved, and continues to evolve, to match the own industry changes and evolution.</p>
<p>In fact, the apps created with Xojo are 64-bit compliant (although you can still generate 32-bit code, if you need), with support for HiDPI graphics, Dark Mode support both on macOS and iOS, the latest iOS SDK, native <a href="https://blog.xojo.com/2020/11/24/xojo-now-supports-native-apple-silicon-m1-compilation/">Silicon and M1</a> compilation and meeting other non-visual changes imposed by any of the current operating systems.</p>
<p>You can expect several Xojo version releases every year, adding new features, improving existing ones and fixing bugs. But we also keep a <a href="http://documentation.xojo.com/resources/roadmap.html">bigger picture about the medium to long term</a> evolution of Xojo, so you can always see the big features we are working on that will be coming in future releases of Xojo. That way, all the effort you&#8217;re putting in the apps, products and solutions you create today won&#8217;t be left behind in the future. You&#8217;ll be able to improve and enrich them for your users, keeping them current as operating systems evolve.</p>
<p>Need to request a feature is important for you or did you find a bug you can&#8217;t workaround? We listen to you. Go to our <a href="https://tracker.xojo.com/xojoinc/xojo/-/issues">Issues tracker system</a> to get in touch with us about the things you want to be added or improved.</p>
<h2>9. Add your own features!</h2>
<p>The Xojo Framework is large enough to accomplish most of the usual app requirements you may need; but sometimes you need to go a bit further, even the thousands of already existing external libraries around whose functions you can use directly from your code … and in these cases you&#8217;re covered too!</p>
<p>Xojo Provides <a href="http://documentation.xojo.com/Xojo&lt;/em&gt;Plugin&lt;em&gt;SDK">SDKs</a> (Software Development Kits) both for Desktop and Web applications; so you just need to start digging in the provided documentation and example projects in order to create your own Xojo Plug-Ins. These will be loaded from the IDE and you&#8217;ll be able to use their exposed features with the same simplicity you do when using the rest of the internal Xojo Framework.</p>
<h2>10. Xojo Ecosystem</h2>
<p>Don&#8217;t be afraid if you don&#8217;t have the time, resources or knowledge needed to develop your own plug-ins.</p>
<p>You can resort to the broad offer of excellent <a href="https://www.xojo.com/store/#addons">third-parties plug-ins</a>, add-ons, libraries and classes you can choose from. These range from commercial software to <a href="http://documentation.xojo.com/Resources:Open&lt;/em&gt;Source_Projects">Open-Source projects</a>, or just plain free classes, modules or libraries ready to download and use in your own Xojo projects.</p>
<h1>We are here to help!</h1>
<p>All in all it&#8217;s time to give Xojo a try, isn&#8217;t? It&#8217;s just a click ahead right now, so <a href="http://xojo.com/download/">download</a> Xojo and rediscover the pleasure of coding!</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Drawing User Interface Controls with DrawInto</title>
		<link>https://blog.xojo.com/2019/10/21/drawing-user-interface-controls-with-drawinto/</link>
		
		<dc:creator><![CDATA[Javier Menendez]]></dc:creator>
		<pubDate>Mon, 21 Oct 2019 10:00:08 +0000</pubDate>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[AprendeXojo]]></category>
		<category><![CDATA[Object-Oriented]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=6090</guid>

					<description><![CDATA[As an Object Oriented Programming language (OOP), Xojo&#8217;s data types, especially the non-primitive ones, use or can use a Class hierarchy. This means that one&#8230;]]></description>
										<content:encoded><![CDATA[<p>As an Object Oriented Programming language (<b>OOP</b>), Xojo&#8217;s data types, especially the non-primitive ones, use or can use a <b>Class hierarchy</b>. This means that one class, either included by default in the Xojo Framework or created from scratch, can act as a base or root class for other classes based upon them.<span id="more-6090"></span></p>
<p>The main advantage of a class hierarchy is that all the derived classes share the same set of methods, properties and events declared in their upper classes (those not set with a Private scope) and, thus, we can make our code more flexible, easier to maintain and get more dynamism from our apps at run time thanks to the <b>Casting</b> of types.</p>
<p style="text-align: center;"><a href="https://drive.google.com/open?id=1FhKmAhYkJYvgagtGuQCK3-67zvdrY78E">Download the Demo Project</a></p>
<p>What is this all about? Very simple. For the subject at hand, every graphic control or User Interface (UI) control included in the Desktop Xojo Framework share the common base class <code>RectControl</code> (this one based, at the same time, on the base class <code>Control</code>); and among the methods available in that class we can find <code>DrawInto</code>.</p>
<p>This means that every UI control has the ability to <em>draw</em> itself in any given <b>Graphic</b> context. However, when drawn in the target graphic context they will lose their usual response to any user interaction. That is, they would be a mere graphic representation of themselves; something that is really useful in many cases. For example, this is the technique used for drawing all the contents of a given page or range of pages in <a href="https://www.aprendexojo.com/shop/axcontrolgrid-2/"><code>AXControlGrid</code></a>.</p>
<p>As you can see in the Xojo documentation, the <code>DrawInto</code> signature is as follows:</p>
<pre>RectControl.<b>DrawInto(g as Graphics,x as Integer, y as Integer)</b></pre>
<ul>
<li>The first thing you can see is that the method is called on the instance (UI control) we want to draw into a given graphic context.</li>
<li>Second, the first argument we provide in the <code>DrawInto</code> method is the <b>graphic context</b> we want to use to draw the control. As you probably know, we can get such graphic context from several kind of classes, for example <b>Picture</b>. In addition, the target graphic context can be of any size we need it to be!</li>
<li>Third, the <code>x</code> and <code>y</code> arguments are the top-left coordinates used to draw the control in the target graphic context and, of course, these coordinates should be in the range of the width and height of the target graphic context passed as the first argument.</li>
</ul>
<p>For most of the cases, you don&#8217;t need to do anything special to use this method in your own classes. That means that the object calling the <code>DrawInto</code> method will draw itself using the same code you put in its <b>Paint</b> event. The unique difference in this case is that the Paint event will use the <b>external</b> graphic context and receive <code>x</code> and <code>y</code> coordinates that may be (or may not be) outside its own width and height range.</p>
<p>But there might be other times you don&#8217;t want to draw the control using the same code as the one written in the Paint event. Maybe because you need a more refined representation of the control or you simply want to leave out some details that are useful when the control is drawn as part of the UI but not when it is printed or used in a PDF document. In addition, it can be the case that inside the Paint event you may need to do some calculations on the <code>x</code> and <code>y</code> coordinates that would not make sense (or would be out of range) when done on an external graphic context.</p>
<p>After all, the key about using&nbsp;<code>DrawInto</code> is this:</p>
<ul>
<li>When a instance calls this method, what really happens is the code in the <code>Paint</code> event will be executed on the new graphic context received as argument. Of course, if you have not implemented the Paint event yourself, then Xojo will execute the default implementation.</li>
</ul>
<h2>Customizing the DrawInto Behavior</h2>
<p>In other cases, especially on Windows, it is possible that we won&#8217;t get the right drawing when using the default implementation of the DrawInto method. If you find yourself in this situation, you can fix it by overwriting the <code>DrawInto</code> method for your own UI classes.</p>
<p>When you do that, evey time you call this method it will execute the code you included in it, and that means that you will be in control of the received graphic context as parameter, its size and origin coordinates, and especially the drawing operations available through the methods from the <code>Graphics</code> class.</p>
<p>The way to implement (overwrite) the <code>DrawInto</code> method in your own UI controls (derived from the <code>RectControl</code> class) is as simple as for any other overwritten method or Event in your own subclasses.</p>
<p>With your class selected in the Xojo IDE Navigator, access the contextual menu to select the <code>Add to "instanceName" &gt; Method</code> option, choosing the <code>DrawInto(graphics as Graphics, Left as Integer, Top as Integer)</code> item in the Name field popup from the Inspector Panel.</p>
<p>Once selected, you will see that the associated Code Editor will contain by default a call to the same method signature on the <b>Super</b> class. This gives the class the control is based on the oportunity to drawn itself.</p>
<p>From a practical point of view, you will probably want to delete that call when you don&#8217;t want to use the same kind of representation for the control on the external graphic context when that is drawn in the UI. In addition you will save some drawing time thus improving the overall speed.</p>
<p>Now you only need to include in the <code>DrawInto</code> method the code you want to use in order to paint your control on the received context and you&#8217;ll be set! From that point on, every time you call:</p>
<pre>aRectControlInstance.DrawInto( tContext, 100, 100 )</pre>
<p>Xojo will execute the code put in your own implementation of the <code>DrawInto</code> method, and that means more flexibility and control about what is drawn and how it is drawn; especially if your UI control is going to be used both in macOS and Windows.</p>
<p><img loading="lazy" decoding="async" class="size-medium wp-image-6092 aligncenter" src="https://blog.xojo.com/wp-content/uploads/2019/10/DrawIntoOverload-Run-300x266.png" alt="" width="300" height="266" srcset="https://blog.xojo.com/wp-content/uploads/2019/10/DrawIntoOverload-Run-300x266.png 300w, https://blog.xojo.com/wp-content/uploads/2019/10/DrawIntoOverload-Run-768x682.png 768w, https://blog.xojo.com/wp-content/uploads/2019/10/DrawIntoOverload-Run.png 964w" sizes="auto, (max-width: 300px) 100vw, 300px" /></p>
<h2>DrawInto in Practice</h2>
<p>In order to see how everything works, let&#8217;s create a simple Xojo Desktop project where we will make use of our own <code>DrawInto</code> implementation on one Canvas based class.</p>
<p>Create a new Xojo Desktop project, drag the <code>Canvas</code> control from the Library panel into the Navigator.</p>
<p>Next, and with the new Canvas class selected, access the Inspector Panel to set the following values:</p>
<ul>
<li><b>Name</b>: MyOwnControl</li>
<li><b>Super</b>: Canvas</li>
</ul>
<p>With our new class still selected in the Navigator, add the <b>Paint</b> Event. For that, you may access the contextual menu and choose the <code>Add to "MyOwnControl" &gt; Event Handler…"</code> option, selecting the Paint entry afterwards in the resulting window.</p>
<p>Then, write the following code in the Code Editor associated with the Paint Event:</p>
<pre>g.DrawingColor = &amp;cff0000
g.FillRectangle(0,0,g.Width, g.Height)</pre>
<p>Nothing especially significant here. As you can see, it sets the foreground color to Red and then fills all the control area using the <code>FillRect</code> method on the control graphic context.</p>
<p>Now it is time to overwrite the <code>DrawInto</code> method. With our class still selected in the Navigator, add the <code>DrawInto</code> method and write the following code in the associated Code Editor:</p>
<pre>// Uncomment the following line of code to see what happens!
// In that Case, the control first executes the code from the Paint Event,
// executing the drawing code from the overriden DrawInto method afterwards.

//super.DrawInto(graphics, left, top)

Var s As String = "From DrawInto"

Var sLen As Double = graphics.TextWidth( s ) / 2

graphics.DrawingColor = &amp;c00FF00

// No matter what the "Left" and "Top" values are, we don't use them
// for our custom drawing.

graphics.DrawRectangle(0,0, graphics.Width, graphics.Height)

graphics.DrawingColor = &amp;c000000
graphics.PenSize = 1
graphics.AntiAlias = True

graphics.DrawText("From DrawInto", (graphics.Width/2) - sLen, (graphics.Height / 2) )</pre>
<p>Basically, what we are doing here is substantially changing the graphical representation of the control between what is seen when it is drawn in the user interface through the Paint Event and what we will get when calling the <code>DrawInto</code> method on the Control instance.</p>
<p>In the second case, it will draw a non-filled green rectangle using the same width and height that the control itself, writting the string &#8220;From DrawInto&#8221; centered in the control area.</p>
<p>You can see that the <code>Super.DrawInto(graphics, Left, Top)</code> code line is commented. After the initial running of the demo app, you can uncoment that line if you want in order to see how it changes the drawing when the <code>Super</code> class is called (remember, that means executing the code on the Paint event for the Class).</p>
<h2>Putting it all Together</h2>
<p>With our class already finished, it is time to start the layout of our minimal user interface. Something really simple. Choose the <code>Window1</code> window in order to access the Layout Editor. Then drag the <code>MyOwnControl</code> item from the Project Broswer into the the Window1 area in the Layout Editor. With that action we will have added a new instance from our class. The resulting name for the instance will be <code>MyOwnControl1</code>.</p>
<p><iframe loading="lazy" title="DrawInto: Dibujado personalizado de controles en un Contexto Gráfico" width="500" height="375" src="https://www.youtube.com/embed/ehyTLCuMIsM?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></p>
<p>Then, drag a standard Canvas control from the Library panel into the <code>Window1</code> area in the Layout Editor. This action will result in the creation of a new Canvas instance with the by-default name <code>Canvas1</code>.</p>
<p>Lastly, add a new button from the Library into the <code>Window1</code> area in the Layout Editor and use the Inspector Panel to set its name to <code>pbDrawInto</code> and its caption to &#8220;DrawInto&#8221;. This will be the button in charge to order our <code>MyOwnControl1</code> instance to draw itself in the graphic context provided by <code>Canvas1</code>.</p>
<p>For that, and with the <code>pbDrawInto</code> selected, add an <code>Action</code> Event Handler and write the following code in the associated Code Editor:</p>
<pre>// We create a Picture we can use to give a Graphics context to the
// Canvas1 backdrop (it would be "Nil" by default)

Var p As New Picture( canvas1.Width, Canvas1.Height, 32 )

canvas1.Backdrop = p

// And we instruct our "MyOwnControl" instance to draw itself on the
// "Canvas1" graphics context.

MyOwnControl1.DrawInto(Canvas1.Backdrop.Graphics,0,0)</pre>
<p>If you want, you can layout your user interface like the one displayed in the following screenshot:</p>
<p><img loading="lazy" decoding="async" class="size-medium wp-image-6091 aligncenter" src="https://blog.xojo.com/wp-content/uploads/2019/10/DrawIntoOverload-IDE-300x267.png" alt="" width="300" height="267" srcset="https://blog.xojo.com/wp-content/uploads/2019/10/DrawIntoOverload-IDE-300x267.png 300w, https://blog.xojo.com/wp-content/uploads/2019/10/DrawIntoOverload-IDE-768x684.png 768w, https://blog.xojo.com/wp-content/uploads/2019/10/DrawIntoOverload-IDE.png 892w" sizes="auto, (max-width: 300px) 100vw, 300px" /></p>
<p>Now we have our app ready to test. Press the <code>Run</code> button in the IDE and verify the results you get between what is drawn by the Paint Event and what you get when you click on the button labeled &#8220;DrawInto&#8221;.</p>
<p><em data-rich-text-format-boundary="true">Javier Rodri­guez has been&nbsp;the Xojo Spanish&nbsp;Evangelist since 2008, he’s also a Developer, Consultant and Trainer who&nbsp;has be using&nbsp;Xojo since 1998. He manages&nbsp;<a href="http://www.aprendexojo.com">AprendeXojo.com</a> and is the developer behind the GuancheMOS plug-in for Xojo Developers, GuancheID, AXControlGrid, AXImageCanvas, Markdown Parser for Xojo, and HTMLColorizer for Xojo among others.</em></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Web Services: Xojo Web, at your service</title>
		<link>https://blog.xojo.com/2018/09/26/web-services-xojo-web-at-your-service/</link>
		
		<dc:creator><![CDATA[Javier Menendez]]></dc:creator>
		<pubDate>Wed, 26 Sep 2018 10:00:59 +0000</pubDate>
				<category><![CDATA[Learning]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Middleware]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Web Service]]></category>
		<category><![CDATA[webdev]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=4950</guid>

					<description><![CDATA[In this two part tutorial we will see how easy it is to create a basic web service using Xojo Web. In the second part, we will create a Desktop client to talk with the web service (you may want to add iOS to the list).]]></description>
										<content:encoded><![CDATA[<p>Using Xojo Web to create complete web apps and solutions means not having to learn a bunch of interpreted languages and dozens of ever-changing frameworks. I&#8217;m looking at you: HTML, CSS (is that even a language?), JavaScript, PHP, et al. Of course, <a href="http://xojo.com/products/web.php">Xojo Web</a> not only makes it possible to create your own web apps, but it also acts as the perfect middleware that your desktop and iOS apps can communicate with. Learn about <strong>APIs</strong> and web services with Xojo in the tutorial blog post.<span id="more-4950"></span></p>
<p>In this two part tutorial you will see how easy it is to create a basic web service using Xojo Web. In the second part, we will create a Desktop client to talk with the web service (you may want to add iOS to the list).</p>
<p>Before we start, let me point out that this tutorial leaves out some details related to error checking, validation, data sanitizing and other specifics related to inputs and outputs in order to focus on the central topic. In addition, if you want to follow and reproduce the steps of this tutorial, then you need to download the <a href="https://github.com/lerocha/chinook-database/raw/master/ChinookDatabase/DataSources/Chinook_Sqlite.sqlite">Chinook Database, </a>named &#8220;test.sqlite&#8221; in this tutorial.</p>
<h2>Services in practice</h2>
<p>Let&#8217;s start creating a web service! Open the Xojo IDE, create a new <b>Web project</b>, and name it <code>WebService</code>. The first thing you&#8217;ll notice is that Xojo adds a web page to the project by default &#8211; even when our web service does not display a UI. The good part is that you can mix both worlds, adding the webservice part to your regular Web app!.</p>
<p>In fact this tutorial will put all the logic in the App object. Start by adding a new <b>property</b> in charge of the reference to our <b>SQLite</b> database (of course, it will work also with <b>PostgreSQL</b> or <b>MySQL</b> engines). Select the <code>App</code> object from the <b>Navigator</b> (the left panel in the Xojo IDE), choosing the <code>Insert &gt; Property</code> option from the contextual menu. With the new property selected, go to the <b>Inspector</b> to set the name, type and scope using these values:</p>
<ul>
<li><b>Name: </b>Database</li>
<li><b>Type: </b>SQLiteDatabase</li>
<li><b>Scope: </b>Private</li>
</ul>
<p>Next, we will add the Chinook Database to the Resources folder of our Web App. For that, select the deployment target under Build Settings (it can be macOS, Windows, Linux or Xojo Cloud, for example), and add a Copy Files build step to it. In the resulting Editor, add the Chinook database SQLite file and make sure you select the &#8220;Resources Folder&#8221; entry in the Destination popup menu, and the &#8220;Both&#8221; entry in the Applies To popup menu.</p>
<p>Now is time to create a new SQLiteDatabase instance and assign it to this property, so it will point to the SQLite database file when the app is running. For that, make sure the <code>App</code> object is selected and add the <code>Opening</code> <b>Event Handler</b> to it using the <code>Insert &gt; Event</code> option. Write the following code in the resulting <b>Code Editor</b>:</p>
<pre>#Pragma Unused args

Var f As FolderItem = SpecialFolder.Resource("Chinook_Sqlite.sqlite")

If f.Exists Then
  
  Try
    database = New SQLiteDatabase
    database.DatabaseFile = f
    
    Call database.Connect
  Catch e As DatabaseException
    MessageBox "Error connecting to the database"
  End Try
  
End If</pre>
<p>As you can see, it is pretty much the same code we already use when creating <b>SQLiteDatabase</b> instances in our Desktop apps, <em>linking</em> to our SQLite database file and stablishing the connection so we can operate with the database engine from our app.</p>
<h2>All the Magic of HandleURL</h2>
<p>Xojo Web projects offer a simple way to handle the request received. It is using the <code>HandleURL</code> event. This is the one that fires every time a client app (it may be a Web Browser, desktop or mobile app) connects to the URL associated with the <b>IP address and port combination</b> that is <em>listening</em> for incoming requests.</p>
<p>For example, a valid URL that can be <b>trapped</b> and processed by <code>HandleURL</code> is:</p>
<pre>http://www.nice-web-domain.com/getCustomers</pre>
<p>Where <code>getCustomers</code> is in this case one of our API methods.</p>
<p>So, with the <code>App</code> object selectd, choose <code>Insert &gt; Event</code> in order to add the <code>HandleURL</code> event.</p>
<p>As we will see, once the event has been added to a web app, it will receive the <code>Request</code> parameter (a <code>WebRequest</code> data type), waiting from us to send back a <code>Boolean</code> value as response: <code>True</code> to process the request or <code>False</code> (the default value) to ignore the response.</p>
<h2>Introducing Request, where the information lives!</h2>
<p>In fact, we will find in the <code>Request</code> object everything we need to process and (if it is the case) respond to the request from our Web service. For example, through we can get the interesting component from the <code>Path</code> property. If we consider this URL:</p>
<p><code>http://www.nice-web-domain.com/getCustomers?spain</code></p>
<p>The <code>Request.Path</code> property will return the <code>getCustomers</code> string; so our web service can process it acordingly from this point on.</p>
<h2>Receiving and Sending JSON data</h2>
<p>In order to keep this tutorial brief, our web API only has two methods in it: <code>GetAll</code> and <code>AddAlbum</code>. Using the first one, the client app will get the album name in the database wrapped in JSON format. With the second method, our client app will ask the web service to add a new record (a new album) to the right table on our example database.</p>
<p>How can we process the request associated data inside the <code>HandleURL</code> event? Here is where we will find very useful another of the <code>Request</code> object properties. The <code>Body</code> property includes the sent data as part of the request that are not already present in the headers. Generally speaking, it includes additional data via the <b>PUT</b> and <b>POST</b> verbs.</p>
<p>Now we can put the following code into our <code>HandleURL</code> Event Handler:</p>
<pre>Select Case Request.Path // What is the method received as part of the request? (URL)
Case "GetAll"
  Var output As JSONItem = GetAllAlbums // Assign the processed data to the output variable, if the received method is 'GetAllAlbums'
  
  Response.Header("charset") = "utf-8"
  Response.MIMEType = "application/json"
  Response.Status = 200
  response.write( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
  
Case "AddAlbum"
  Var data As String = Request.Body.DefineEncoding(encodings.UTF8) // We have to apply the right encoding to the received data
  Var Input As JSONItem = New JSONItem( data ) // Creating a new JSON object from it
  addNewAlbum( Input.Value("newAlbum") ) // In this case, the request is to add a new Album to the database; passing thus the received data as part of the input
End Select

Return True</pre>
<p>The main point here is that we assign the received data to the <code>data</code> variable (if any), and define a known encoding to them so we won&#8217;t get into trouble while processing them afterwards. Of course, our example always expects to receive the additional data in JSON format, so this is why we create a new JSON instance from this data.</p>
<p>We use the <code>Select…Case</code> command to decide what method has to execute the web service, and that is based on the component stored in the <code>Path</code> property as you recall. So, if the request uses the <code>GetAll</code> method in the URL, we will call the real method <code>GetAllAlbums</code> in our Xojo code. After processing the information it will return a new <code>JSONItem</code> as the response we will send to the client.</p>
<p>How can we send the response to the request? Really simple: calling the <code>Write</code> method on the Response object, passing as parameter the text we want to send back. In our example, this is the <code>JSONItem</code> referenced by the <code>Output</code> variable. We also use the Response object to set the character encoding to UTF-8 and the MIME type to &#8220;Application/json&#8221;, in addition of setting the status value to 200 (that is, the request has been successfully handled).</p>
<p>If we receive a request with the <code>AddAlbum</code> method of our API, then we call the real <code>addNewAlbum</code> method in our Xojo code, passing as parameter the <code>JSONItem</code> object in charge of store the received data from the request (this is the one referenced by the <code>input</code> variable). In fact, the record structure is stored inside the <code>newAlbum</code> root node of the JSONItem.</p>
<h2>When it comes to the Database</h2>
<p>While <code>HandleURL</code> is in charge of processing the received request, we will use a couple of methods in our example app that will act as a <em>link</em> between the API and the database in the backend, both for retrieving and storing the requested information. (In a real world app it is very advisable to introduce checks and data sanitization before dealing with the database!)</p>
<p>Choose the <code>App</code> object again and use the <code>Insert &gt; Method</code> option in order to add the <code>GetAllAlbums</code> method, using the following method signature for that:</p>
<ul>
<li style="list-style-type: none;">
<ul>
<li><b>Method Name: </b>getAllAlbums</li>
<li><b>Return Type: </b>JSONItem</li>
<li><b>Scope: </b>Private</li>
</ul>
</li>
</ul>
<p>This is the code in charge of generating the JSONitem that we will <em>write </em>as part of the request response, including the <b>node</b> for every expected database record from the <code>Album</code> table in our example database:</p>
<pre>Var rc As RowSet = database.SelectSQL("Select * from album order by title asc") // Get the Recordset as result of the SQL selection: all the records
Var item As New JSONItem

If rc.RowCount &gt; 0 Then // We have records on the RecordSet
  
  While Not rc.AfterLastRow // so lets iterate them!
    Var d As New Dictionary // creating a new dictionary for each record, and that we will convert in a node
    d.Value("artistid") = rc.Column("artistid").StringValue // assingning the record ID to the name 'ArtistId' of the JSONItem
    d.Value("title") = rc.Column("title").StringValue // and the Title value to the 'Title' field of the JSONItem
    item.Value(rc.Column("albumid").StringValue) = d // You know you can assign a Dictionary as the value for a JSONItem node. Very useful!
    
    rc.MoveToNextRow
  Wend
  
  rc.Close
  
End If

var output As New JSONItem

output.Value("AllAlbums") = item // Then let's hang all these records form a main Node

Return output // And return it to the caller</pre>
<p>Next, create a new method named <code>addNewAlbum</code>. This is the one our web service will use to add a new record to the database, using for that the received data as part of the request. Use the following signature for the method definition:</p>
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li><b>Method Name: </b>addNewAlbum</li>
<li><b>Paramters: </b>item as JSONItem</li>
<li><b>Scope:</b> Private</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>And put the following code in the associated Code Editor:</p>
<pre>Var title As String = item.Value("Title") // get the data associated to the "Title" field
Var artistid As String = item.Value("ArtistId") // and the 'ArtistID'

database.ExecuteSQL("insert into album(title,artistid) values(?, ?)", title, artistid ) // and insert that data as a new record into the database table
</pre>
<p>As you can see, the code is very simple: it gets the values for the received keys in the JSONitem nodes and uses them as part of the SQL sentence in order to add a new record to the database.</p>
<h1>A Web service… ready to serve!</h1>
<p>As you have seen, the code and app structure are really minimal! Of course, this is just a simple example but it gives you a good idea of the kind of possibilities web services offer and how fast you can put it together using Xojo and <strong>OOP</strong> concepts you already know! Of course, you can run your web app (and services) right from the IDE (just make sure to select 8081 as the Debug Port)… what is probably the recommended way to follow this simple example. For other more complex web apps, remember that you can use the one click solution <a href="https://www.xojo.com/cloud/"><strong>Xojo Cloud</strong></a> and of course any compatible Linux, Windows or Mac server.</p>
<p><em>Javier Rodri­guez has been the Xojo Spanish Evangelist since 2008, he’s also a Developer, Consultant and Trainer who has be using Xojo since 1998. He manages <a href="http://www.aprendexojo.com">AprendeXojo.com</a> and is the developer behind the GuancheMOS plug-in for Xojo Developers, Markdown Parser for Xojo, HTMLColorizer for Xojo and the Snippery app, among others</em></p>
<p>*<a href="https://www.aprendexojo.com/2016/06/crear-servicio-web-con-xojo/">Read this post in Spanish</a></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Create a Preferences Class with Operator_Lookup</title>
		<link>https://blog.xojo.com/2018/06/20/create-a-preferences-class-with-operator_lookup/</link>
		
		<dc:creator><![CDATA[Javier Menendez]]></dc:creator>
		<pubDate>Wed, 20 Jun 2018 10:00:58 +0000</pubDate>
				<category><![CDATA[Cross-Platform]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Constructor]]></category>
		<category><![CDATA[Method Overload]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Singleton]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=4381</guid>

					<description><![CDATA[Create a Preferences Class with Operator_Lookup: We have at our disposal an operator we can overload: Lookup. Let's explore those advantages and features while building a Preferences class we can use in any of our projects.]]></description>
										<content:encoded><![CDATA[<p>Xojo is an <a href="https://en.wikipedia.org/wiki/Object-oriented_programming">Object Oriented Programming Language</a> and, among other things, that means that it supports <a href="https://blog.xojo.com/2016/05/25/methods-overloading-computed-properties-setters-and-getters/">Methods Overloading</a>. We have seen in other posts that some of these overloaded methods can be Class Constructors, but, there are others things you can do. For example, we can overload the operators. These are the methods in charge of adding two instances of the same class, subtracting, multiplying or dividing them. But we also have at our disposal another operator we can overload: <b>Lookup</b>. What advantages does this give us and how it does it work? Let&#8217;s explore it while building a Preferences class we can use in any of our projects.<span id="more-4381"></span></p>
<p>When we define and implement the <b>Operator_Lookup</b> method in our classes, we will be able to use the dot notation to access and assign a value to a class member that has not been defined for the class! That is, it will be the code implemented in this method that will decide how it will act, not the Xojo Compiler. Among other possibilities, this will bring us the flexibility to create a Preferences class that is not attached to a particular project, and that is multiplatform, of course, backed by as many pairs of Keys/Values in a Dictionary as we need to store our apps preferences. This way we can use the simple dot notation both to store and assign the stored values. Let&#8217;s put this into practice.</p>
<p>The first step is adding a new Class item to the project without assigning a Super class; that is, this will be a base class. For this example, we will use <code>MyPreferences</code> as the name of the class. Then, we will add a property with <code>Data</code> as the Name and <code>Xojo.Core.Dictionary</code> as the data type, setting its scope to Private (this means that the property will be accessible only from the own class). This property will act as the storage for the Key/Value pairs used for our Preference Class.</p>
<p>Add now a new <b>Constructor</b> method in charge of initializing the just defined Dictionary property:</p>
<ul>
<li><b>Name</b>: Constructor</li>
<li><b>Scope</b>: Public</li>
</ul>
<p>And put this line of code in the Code Editor for the Constructor method:</p>
<pre>Data = New Xojo.Core.Dictionary</pre>
<p>Now we will add the method that we are really interested in. This is, the overload for the Operator_Lookup method:</p>
<ul>
<li><b>Name</b>: Operator_Lookup</li>
<li><b>Parameters</b>: key as string, assigns value as auto</li>
<li><b>Scope</b>: Public</li>
</ul>
<p>Writing the following line of code in the resulting Code Editor:</p>
<pre>data.Value( key ) = value</pre>
<p>Once implemented, we can take advantage of the feature. If we add the Open Event to the project and write the below snippet of code, we will see how we can use the dot notation to use and access class members that have never been added to the class. These members are <em>captured</em> by the <code>Operator_Lookup</code> method, adding the member as the key for a new entry in the dictionary (this is the text we write after the dot) and assigning to it the value we put after the equal symbol (the assignation operator); thanks to the use of the <code>assigns</code> keyword in the parameters declaration for the <code>Operator_Lookup</code> method.</p>
<pre>Dim pr As New MyPreferences
pr.page = 10
pr.index = "20"
pr.baseColor = &amp;c204060</pre>
<p>As you can see, <code>Page</code>, <code>Index</code> and <code>BaseColor</code> are not members of our class; these are captured as Keys for the Dictionary thanks to the Operator_Lookup operator. In addition, you can see how we can assign several types of values to these: an Integer, a String and a Color value.</p>
<h2>Retrieving data with Operator_Lookup</h2>
<p>Now, how can we retrieve values for these not existing members using the dot notation? As you probably guessed, we need to add an additional method that overloads Operator_Lookup. In this case the method signature will accept as the parameter the Key we want to retrieve (the class member put after the dot), returning always a String, in order to simplify this example. Thus, add a new method for the class using the following signature:</p>
<ul>
<li><b>Name</b>: Operator_Lookup</li>
<li><b>Parameters</b>: Key As String</li>
<li><b>Return Type</b>: String</li>
<li><b>Scope</b>: Public</li>
</ul>
<p>Writing the following code in the associated Code Editor:</p>
<pre>Dim a As Auto
Dim s As String
If data.HasKey(key) Then
  a = data.Value(key)
  Dim info As Xojo.Introspection.TypeInfo
  info = xojo.Introspection.GetType(a)
  If info = GetTypeInfo(Text) Or info = GetTypeInfo(String) Then
    s = a
  Elseif info = GetTypeInfo(Integer) Then
    s = CType(a, Integer).totext
  Elseif info= GetTypeInfo(Color) Then
    Dim c As Color = a
    s = Str(c)
  End If
End If
Return s</pre>
<p>As you can see, and after verifying that the Dictionary has the Key, we use the <b>Introspection</b> mechanisms provided by the language in order to see what type is associated with the key. Once we have its type, we will convert the value to a String using the appropriate approach for each case: an Integer, a Text/String or a Color. Of course, for brevity, this example doesn&#8217;t take into account other possible value types; but that is something you can implement yourself!</p>
<p>Let&#8217;s go back to the Open Event for the project and add the following line of code at the end:</p>
<p><code>MsgBox pr.page + EndOfLine + pr.index  + EndOfLine + pr.baseColor</code></p>
<p>Run it and observe how we can assign values and retrieve them (always as a String) simply using the dot notation. We can take this class from one project to other and use the dot notation to reference the elements we want to save and retrieve as preferences.</p>
<p><iframe loading="lazy" title="Obtén la máxima flexibilidad con Operator_Lookup" width="500" height="375" src="https://www.youtube.com/embed/Tya8tbi9xIM?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></p>
<h2>Final Word</h2>
<p>If you decide to use this approach for your projects, there are some considerations you have to take into account. For example, you will not be able to take advantage of the Autocompletion feature provided by the IDE. In addition, we will have to pay special attention to write exactly the same &#8220;member&#8221; in all the cases we want refer to it; otherwise we will be using a different key with unexpected results. After all, once implemented, Operator_Lookup for the class the Compiler will not complain about the undefined members you are trying to access!</p>
<p>It would also be very easy to expand the class so it can work with other data types; adding an additional method to serialize the Key/Values pairs so they can be stored on file/database for a later retrieval and reconstruction via an additional Constructor. Finally, it is very probable that you only want to use a MyPreferences instance in your app, so you could implement this class as a <a href="https://blog.xojo.com/2016/06/08/design-patterns-in-xojo-singleton/">Singleton</a>. Do you dare? If you do, <a href="https://twitter.com/AprendeXojo">tell me about it</a>!</p>
<p><em>Javier Rodri­guez has been the Xojo Spanish Evangelist since 2008, he’s also a Developer, Consultant and Trainer who has be using Xojo since 1998. He manages <a href="http://www.aprendexojo.com">AprendeXojo.com</a> and is the developer behind the GuancheMOS plug-in for Xojo Developers, Markdown Parser for Xojo, HTMLColorizer for Xojo and the Snippery app, among others</em></p>
<p>*<a href="https://www.aprendexojo.com/2018/06/comprobar-y-anadir-valores-en-tiempo-de-ejecucion/">Read this post in Spanish</a></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Casting, get ready and keep the Type!</title>
		<link>https://blog.xojo.com/2018/03/21/casting-get-ready-and-keep-the-type/</link>
		
		<dc:creator><![CDATA[Javier Menendez]]></dc:creator>
		<pubDate>Wed, 21 Mar 2018 09:00:31 +0000</pubDate>
				<category><![CDATA[Learning]]></category>
		<category><![CDATA[Cast]]></category>
		<category><![CDATA[OOP]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=3997</guid>

					<description><![CDATA[Object Oriented Programming (OOP) puts in our hands the ability to create apps in a flexible and powerful way. Xojo embraces that philosophy in the&#8230;]]></description>
										<content:encoded><![CDATA[<p>Object Oriented Programming (<a href="http://developer.xojo.com/userguide/object-oriented-programming"><b>OOP</b></a>) puts in our hands the ability to create apps in a flexible and powerful way. Xojo embraces that philosophy in the Xojo language itself, allowing us to implement code in a flexible way for reuse, extension and maintainability that reduces the development cycles. One of these language tools is, in fact, common in other low level programming languages: <a href="http://developer.xojo.com/userguide/advanced-oop-features$casting"><b>Casting</b> or type conversion</a>. If you are interested in this (and you should be), continue reading and discover what it is, why you should be interested in it and how can you use it in your next Xojo app!<span id="more-3997"></span></p>
<p>If you are using Xojo already, or any other programming language, then I&#8217;m pretty sure you are using casting without even noticing it. For example, when you use simple types like Double or Integer, or even when assigning a String value to a Text variable. In these cases, everything happens behind the scenes. For example, these could be some type conversions you made in a regular basis:</p>
<pre>Dim n as Double = 10.20
Dim i as Integer
i = n // The 'i' variable will have the value 10, losing the decimal part as result of the implicit conversion process

Dim s as String = "Hello World!"
dim t as Text
t = s.ToText // Both variables have the same text using the "ToText" method in order to convert it to the expected type by the target variable.</pre>
<p>Both cases shows implicit conversions. This is, these are done without your intervention. However, in other scenarios we need to make these explicit, like when we need to use an object as if it was an instance created by the parent class in the hierarchy, and using it in a later step as a member of its real subclass (child class in the hierarchy), so we can continue using their methods and accesing the properties declared under that class.</p>
<p>Why would you want to do something like this? Well, there are a couple of cases that just jump into my mind:</p>
<ul>
<li>When it comes to objects created by classes that are not directly connected through the class hierarchy, but that share one or more common <a href="http://developer.xojo.com/userguide/interfaces">Class Interfaces</a>.</li>
<li>When these are objects created by several <a href="http://developer.xojo.com/userguide/oop-design-concepts$inheritance-subclassing">subclasses</a>, descending from a common parent class.</li>
</ul>
<p>For the first point, it would be the case where we need to maintain a collection of the same kind of objects, probably defined by a Class Interface type, but that in reality are created from several classes. This way, we can put all these objects in the same collection, iterating them and sending to them any of the methods defined by the Class Interface.</p>
<p>Something similar is what happens with the second scenario, where we can access to the common properties and methods offered by the parent class and, thus, shared an availables too in the instances created from their subclasses.</p>
<p>In fact, it is very probable that you are already using this second scenario in your projects as when you iterate all the controls (parent Class <b>Control</b>) put in the layout of a particular Window instance, a WebPage or an iOSView (each platform has its own parent class for controls). Here is a code example (in this case <code>me</code> refers to the <code>Window</code> instance where we put our code):</p>
<pre>For n as Integer = 0 to me.ControlCount - 1
  StrBox me.Control(n).Name
Next</pre>
<p>Showing this way the name of all the Window controls, no matter if they are TextFields, ListBox, PushButton, etc. After all, these controls classes are inherited from the <b>Control</b> class. Thus, the previous code snippet also could be written like this:</p>
<pre>Dim c as Control
For n as Integer = 0 to me.ControlCount - 1
  c = me.Control(n)
  MsgBox c.Name
Next</pre>
<p>But, what happens if we just are interested in showing the name of the controls from a specific <b>subclass</b>? For example it could be the case where we just need to show the name of the <b>TextField</b> controls used in the window layout. All the instances maintain internal information about themselves, like their Type, so we can access to that information during the execution of our apps through the <b>introspection</b> mechanisms provided by the Xojo language; but if we just need to check an instance type, then we can simply use the <a href="http://developer.xojo.com/isa"><b>IsA</b> operator</a>. This operator allows us to compare an <b>instance</b> against a <b>Class</b> or <b>Class Interface</b>, returning a <b>boolean</b> value as result of such comparison. Then, we can use this fragment to show the name of the TextField controls used in the window layout:</p>
<pre>Dim c as Control
For n as Integer = 0 to me.ControlCount - 1
  c = me.Control(n)
  If c IsA TextField Then
    MsgBox c.Name
  End If
Next</pre>
<h2>Casting in action</h2>
<p>When we work with an instance as if it was an instance from the parent class, or as a member of a Class Interface, then we call it <b>Downcasting</b>; something we could translate as <b>going down in the class hierarchy</b>. For example, this is what we have done in the previous fragments, where we use all the controls of the user interfaces as if they where instances from the <b>Control</b> class.</p>
<p>As we go deeper in the class hierarchy, we reduce the amount of properties, methods and events we can access. I mean, we are limiting ourselves in the functionality achievable by the instances. This is something we will be glad to embrace if we take into account the benefits that this practice gives us in return as flexibility and code cleanness.</p>
<p>Nevertheless, and continuing with the same example, what if we would want to retrieve all the TextField instances, not as Control instances but as their own, original, class type in order to access their defined properties or methods? How can we accomplish that?</p>
<p>Let&#8217;s say that we don&#8217;t just want to show the TextField instances name, but also change their background color, something that is not implemented under the Control class. That is, we need to use some behaviour specific to the TextField class. Here is where <b>Casting</b> comes into play: the ability to <b>cast</b> or project a class instance as the type we want it to be:</p>
<pre>Dim c as Control
dim t as TextField
For n as Integer = 0 to me.ControlCount - 1
  c = me.Control(n)
  If c IsA TextField Then
    MsgBox c.Name
    t = TextField(c) // Casting from the "Control" instance variable as a concrete subclass: "TextField"
    t.TextColor = &amp;cFF0000
  End If
Next</pre>
<p>That is, in order to use the <b>Casting</b> feature in Xojo, we need to put between parenthesis the name of the instance we want to convert, preceded by the name of the class we want the instance to be converted to.</p>
<p>Notice that when we use this OOP mechanism, we will not be backed by the usual help provided by the compiler on type checking. This means that if, for example, we cast an instance to a wrong target class for such instance has not internal information (it has not been originally created from that class, subclass or does not implement that class interface), then probably your app will not work as expected and, very probably, will fail or crash during its execution. To prevent this, you need to check for the inner class of any instance using any of the language provided mechanism in order to make sure you&#8217;re casting to the right type.</p>
<p>Finally, we could simplify the previous code like this:</p>
<pre>For n as Integer = 0 to me.ControlCount - 1
If me.Control(n) IsA TextField Then
  MsgBox me.Control(n).Name
  TextField(me.Control(n)).TextColor = &amp;cff0000
End If
Next</pre>
<p>This way will loses some readability (code intention), but results in a more compact code.</p>
<p>Throughout this example we have seen how easy it is to work with instances as if they where more generic, and <em>converting</em> them again to their original type when we need to use their specialized behaviour or access their specific status, using the Casting OOP mechanism for that.</p>
<p>You can watch this video (en español) to see this in action:</p>
<p><iframe loading="lazy" title="Conversión de Tipos" width="500" height="375" src="https://www.youtube.com/embed/Iz0zG2KLNBo?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></p>
<p><em>Javier Rodri­guez has been the Xojo Spanish Evangelist since 2008, he’s also a Developer, Consultant and Trainer who has be using Xojo since 1998. He manages <a href="http://www.aprendexojo.com">AprendeXojo.com</a> and is the developer behind the GuancheMOS plug-in for Xojo Developers, Markdown Parser for Xojo, HTMLColorizer for Xojo and the Snippery app, among others</em></p>
<p>*<a href="https://www.aprendexojo.com/2018/03/conversion-de-tipos-casting/">Read this post in Spanish</a></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Unlock the all in one, low-code, cross-platform solution</title>
		<link>https://blog.xojo.com/2018/03/15/unlock-all-in-one-low-code-cross-platform-solution/</link>
		
		<dc:creator><![CDATA[Geoff Perlman]]></dc:creator>
		<pubDate>Thu, 15 Mar 2018 09:00:32 +0000</pubDate>
				<category><![CDATA[Cross-Platform]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Citizen Developer]]></category>
		<category><![CDATA[Intro to Xojo Programming Textbook]]></category>
		<category><![CDATA[Low-Code]]></category>
		<category><![CDATA[Multi-Platform Development]]></category>
		<category><![CDATA[Native App Development]]></category>
		<category><![CDATA[Object-Oriented]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[RAD]]></category>
		<category><![CDATA[Rapid Application Development]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=4006</guid>

					<description><![CDATA[Just as people have varying levels of skill and interest in video games, the same is true of app development.  It's tremendously empowering to be able to build even a simple app that helps you accomplish tasks more quickly and efficiently. A low-code development tool like Xojo is a great place to start.]]></description>
										<content:encoded><![CDATA[<p>Like his father, my teenage son loves video games. The single player games where you take a character through some kind of adventure are the ones I like most. These usually have a fair number of AI-controlled enemies that must be defeated. My son, on the other hand, prefers to play against other human beings. When I asked him why, he said, &#8220;The AIs are <em>so</em> predictable.&#8221; To prove this to me, he took over when I was having trouble defeating a particularly difficult enemy and quickly dispatched him, narrating his strategy as he went and barely being scratched in the process. My son is an elite player compared to me partially because he puts a lot more time into it than I do but also because he loves video games far more than I do.</p>
<p>Just as people have varying levels of skill and interest in video games, the same is true of app development. There are those that are happy to devote enormous amounts of time to learning everything they possibly can. They don&#8217;t care how long it takes. They want to have control over everything and are willing to do whatever is necessary to make that happen. I&#8217;m so glad those people exist because there&#8217;s a lot of great software that might not otherwise have been created without them. I&#8217;m <em>not</em> one of those people. I really want to focus mostly on what makes my application unique, abstracted from the nitty-gritty of app development.</p>
<p>That&#8217;s why I have always been attracted to tools like Xojo. I am a <a href="https://blog.xojo.com/2015/11/19/the-citizen-developer/">citizen developer</a>. Of all the job titles I have had over the years, all of them in tech,  none have <strong>ever</strong> included words like <em>programmer</em> or <em>engineer</em>. I do some software development but it&#8217;s just a part of my job. It&#8217;s something I do to help me in my work or to help my co-workers.</p>
<p><span id="more-4006"></span></p>
<p>When I founded Xojo, Inc., tools like Xojo were called RAD (<a href="https://en.wikipedia.org/wiki/Rapid_application_development">Rapid Application Development</a>) tools. Now the term du jour is <em>Low-Code</em>. Put simply, it means that a development tool provides a lot of <strong>built-in</strong> functionality so you don&#8217;t have to write too much code compared to more traditional languages and tools. That&#8217;s Xojo. You can build your user interface visually via <strong>drag and drop</strong>.</p>
<p><a href="https://blog.xojo.com/wp-content/uploads/2018/03/IDE-Desktop.png"><img loading="lazy" decoding="async" class="aligncenter wp-image-4062 size-full" src="https://blog.xojo.com/wp-content/uploads/2018/03/low-code_desktop-IDE.png" alt="" width="2500" height="2000" /></a></p>
<p><a href="https://blog.xojo.com/wp-content/uploads/2018/03/Xojo-iDE-.png"><img loading="lazy" decoding="async" class="aligncenter wp-image-4063 size-full" src="https://blog.xojo.com/wp-content/uploads/2018/03/low-code_mobile-IDE.png" alt="" width="2500" height="2000" /></a></p>
<p><a href="https://blog.xojo.com/wp-content/uploads/2018/03/IDE-Web.png"><img loading="lazy" decoding="async" class="aligncenter wp-image-4064 size-full" src="https://blog.xojo.com/wp-content/uploads/2018/03/low-code_web-IDE.png" alt="" width="2500" height="2000" /></a>The set of built-in commands (the <em>framework</em>) provides you with everything you&#8217;ll likely need to handle the things that do require some coding. Xojo is a cross-platform tool making it easy to create apps for different platforms such as MacOS, Windows, Linux, the web, iOS and even <a href="https://blog.xojo.com/2018/03/14/have-you-pie-build-with-it-too/">Raspberry Pi</a>, without having to learn all the details of each one. Unlike some cross-platform solutions, Xojo builds complete <strong>native</strong> apps which means your apps have the look, feel and performance of those written in the more complicated tools that require so much more code.</p>
<p><img loading="lazy" decoding="async" class="alignleft size-full wp-image-4049" src="https://blog.xojo.com/wp-content/uploads/2018/03/Xojo-LR.png" alt="" width="2112" height="1510" /></p>
<p>It&#8217;s not all upside. There are sometimes very specific features for which Xojo has no built-in support. An example of this is notifications. The good news is that should you find yourself needing functions like this, there&#8217;s a vibrant Xojo community of users who have likely already created that <a href="http://developer.xojo.com/third-party-products">functionality</a> and you can just add it to your project. And Xojo is updated multiple times per year so new functionality is always appearing.</p>
<p>If you&#8217;re like me and you want to be able to quickly and easily build applications that make life easier for you and perhaps your co-workers, Xojo is something you should seriously consider. Xojo is also <strong>free to use and learn</strong>. You only need buy a license if you decide you want to deploy your application. We provide lots of free resources including a <a href="https://youtube.com/goxojo">video library</a> with over 250 videos, tutorials, and <a href="http://developer.xojo.com/home">documentation</a> as well as a <a href="https://www.xojo.com/resources/learn.php">textbook</a> designed to help you learn app development.</p>
<p>It&#8217;s tremendously empowering to be able to build even a simple app that helps you accomplish tasks more <strong>quickly and efficiently</strong>. A low-code development tool like Xojo is a great place to start.</p>
<p>&nbsp;</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
