{"id":2433,"date":"2016-05-21T12:16:02","date_gmt":"2016-05-21T00:16:02","guid":{"rendered":"https:\/\/www.deltics.co.nz\/blog\/?p=2433"},"modified":"2016-05-21T12:46:01","modified_gmt":"2016-05-21T00:46:01","slug":"fire-walk-with-me","status":"publish","type":"post","link":"https:\/\/www.deltics.co.nz\/blog\/posts\/2433\/","title":{"rendered":"Fire, Walk With Me"},"content":{"rendered":"<span class=\"rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">[Estimated Reading Time: <\/span> <span class=\"rt-time\">3<\/span> <span class=\"rt-label rt-postfix\">minutes]<\/span><\/span><p>This final post in the mini-series re-creating a random number app for OS X, Android and .NET has taken a while not because it&#8217;s complicated but because I&#8217;ve been distracted by a far more significant cross-platform project and some significant and exciting developments in the world of Fire and Elements.  More on that later<\/p>\n<p>First, let&#8217;s get this .NET app out of the way.<\/p>\n<p><!--more--><\/p>\n<p>For this exercise we actually have to leave Fire and use the Visual Studio hosted Elements compiler.  As mentioned before, Fire does not provide any UI designers so for WinForms applications the UI design has to be done in Visual Studio (or create the UI in code explicitly of course).<\/p>\n<p>You can <i>compile<\/i> a .NET application in Fire, in which case it produces a <strong>mono<\/strong> application, <a href=\"http:\/\/www.mono-project.com\/docs\/gui\/winforms\/\">including support for WinForms<\/a>.  But although the Elements compilers also fully support WPF applications for .NET (again, with Visual Studio providing the design surface) <strong>mono<\/strong> itself does not provide any support for WPF.  As a result those projects cannot be compiled in Fire.  They can of course be developed fully in Visual Studio.<\/p>\n<p>There really isn&#8217;t much to be gained from using <strong>mono<\/strong> to run .NET code on a Mac when you can just create native OS X apps (and which look far better than mono Winforms apps).  So for this exercise I&#8217;ll just go ahead and create the .NET apps in Visual Studio.<\/p>\n<p>First up, here is our UI design which should be very familiar by now:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/i0.wp.com\/www.deltics.co.nz\/blog\/wp-content\/uploads\/form-design.jpg?resize=300%2C133&#038;ssl=1\" alt=\"form design\" width=\"300\" height=\"133\" class=\"aligncenter size-medium wp-image-2436\" srcset=\"https:\/\/i0.wp.com\/www.deltics.co.nz\/blog\/wp-content\/uploads\/form-design.jpg?resize=300%2C133&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.deltics.co.nz\/blog\/wp-content\/uploads\/form-design.jpg?resize=768%2C340&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.deltics.co.nz\/blog\/wp-content\/uploads\/form-design.jpg?resize=500%2C221&amp;ssl=1 500w, https:\/\/i0.wp.com\/www.deltics.co.nz\/blog\/wp-content\/uploads\/form-design.jpg?w=976&amp;ssl=1 976w\" sizes=\"(max-width: 300px) 100vw, 300px\" data-recalc-dims=\"1\" \/><\/p>\n<p>Now for the code, most of which in this simple case is boiler-plate, produced by the template or the form designer.  The only work I have to do is add the existing Shared Code code project to the references of the .NET project.<\/p>\n<p>The solution already contains the shared code project I need because this is the same solution I was working on in Fire itself.  Similarly when I re-open the solution in Fire I will see the new .NET project I have added.<\/p>\n<p>Worth nothing here is that the build configuration settings used to determine which projects are included when the solution is built is one of the few things that are <strong>not<\/strong> shared between Fire and Visual Studio.  So with the same solution I can fluidly switch between Visual Studio and Fire to build the projects appropriate to the platforms I am working on in each IDE.<\/p>\n<p>Back to the .NET project.  With the shared code project added to references, I can then add RandomNumber to the uses list of my form:<\/p>\n<pre class=\"brush: oxygene; title: ; notranslate\" title=\"\">\r\n\r\n    namespace RandomNumber.NET;\r\n\r\n  interface\r\n\r\n  uses\r\n   System.Drawing,\r\n   System.Collections,\r\n   System.Collections.Generic,\r\n   System.Linq,\r\n   System.Windows.Forms,\r\n   System.ComponentModel,\r\n   RandomNumber;\r\n\r\n  type\r\n    \/\/\/ &lt;summary&gt;\r\n    \/\/\/ Summary description for MainForm.\r\n    \/\/\/ &lt;\/summary&gt;\r\n    MainForm = partial class(System.Windows.Forms.Form)\r\n    private\r\n    {$REGION designer-generated code}\r\n     method btnSeed_Click(sender: System.Object; e: System.EventArgs);\r\n     method btnGenerate_Click(sender: System.Object; e: System.EventArgs);\r\n    {$ENDREGION}\r\n    private\r\n      property Random: RandomNumber read write;\r\n    protected\r\n      method Dispose(disposing: Boolean); override;\r\n    public\r\n      constructor;\r\n    end;\r\n\r\n<\/pre>\n<p>So that&#8217;s two lines of code added:  One to bring in the namespace containing my cross-platform <strong>RandomNumber<\/strong> class and the other to declare a <strong>private read\/write property<\/strong> to hold a reference to an instance of that class.<\/p>\n<p>Which leaves just the implementation of the two button click events which again is mostly designer generated code and some very familiar calls to the methods of the random number generator:<\/p>\n<pre class=\"brush: oxygene; title: ; notranslate\" title=\"\">\r\n  method MainForm.btnSeed_Click(sender: System.Object; e: System.EventArgs);\r\n  begin\r\n    Random := new RandomNumber;\r\n    lblText.Text := 'Random Number Generator Seeded';\r\n  end;\r\n\r\n  method MainForm.btnGenerate_Click(sender: System.Object; e: System.EventArgs);\r\n  begin\r\n    if assigned(Random) then\r\n      lblText.Text := Random.Next(100).ToString;\r\n  end;\r\n<\/pre>\n<p>And that&#8217;s it.<\/p>\n<p>It bears mentioning again I think that although I called <strong>RandomNumber<\/strong> a &#8220;cross-platform&#8221; class, this isn&#8217;t strictly accurate.  In fact, it&#8217;s not at all accurate.<\/p>\n<p>Remember that for .NET my class is simply mapped &#8211; directly &#8211; to the .NET framework Random class.  There is no separate class that is some cross-platform wrapper around the platform classes.  This reference to a <strong>RandomNumber<\/strong> instance is in fact a reference to an instance of <strong>System.Random<\/strong> (on .NET).  On OS X it is an entirely new class which encapsulates the required posix PRNG API&#8217;s.<\/p>\n<p>In the case of the RandomNumber class, this has been a fairly trivial (some might even say &#8216;pointless&#8217;) exercise.  But it provides an introduction to the basic idea which we can build on for far more useful exercises.<\/p>\n<p>And the utility of consistent, cross-platform implementation is likely to become ever more significant for Elements with the recent introduction (today in fact!) of the first beta of <strong>Island<\/strong>.<\/p>\n<p>Because this adds two entirely new platforms to the Elements stable, in addition to .NET\/mono, iOS\/OS X and Java\/Android.  The two new platforms are:<\/p>\n<ul>\n<li> Linux CPU-Native code <\/li>\n<li> Win32\/64 CPU-Native code <\/li>\n<\/ul>\n<p><i>Very<\/i> interesting and exciting times indeed and I shall be posting on these as and when I learn more about them (the beta is downloading as I finish up this post).  \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p><span class=\"rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">[Estimated Reading Time: <\/span> <span class=\"rt-time\">3<\/span> <span class=\"rt-label rt-postfix\">minutes]<\/span><\/span> This final post in the mini-series re-creating a random number app for OS X, Android and .NET has taken a while not because it&#8217;s complicated but because I&#8217;ve been distracted by a far more significant cross-platform project and some significant and exciting developments in the world of Fire and Elements. More on that later First, [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":[]},"categories":[4,242,180],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1TKYv-Df","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":2393,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/2393\/","url_meta":{"origin":2433,"position":0},"title":"Come on Baby, Light My Fire","date":"25 Apr 2016","format":false,"excerpt":"Earlier this year, the Fire IDE for Elements was officially released after a fairly extensive beta. I have previously stuck with Visual Studio for the [relatively little] Elements work I have been doing but problems with my VM solution on a recently acquired MacBook Pro gave me the impetus to\u2026","rel":"","context":"In &quot;Delphi&quot;","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.deltics.co.nz\/blog\/wp-content\/uploads\/Fire-Initial-Project-300x214.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2327,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/2327\/","url_meta":{"origin":2433,"position":1},"title":"On The Shoulders of Giants&#8230;","date":"18 Dec 2014","format":false,"excerpt":"When discussing mobile device application development using Oxygene or other RemObjects Elements technologies, the question of user interface designers doesn't usually take long to come up (particularly with Delphi developers). Up to now the answer has always been Xcode Interface Builder for iOS\/OS X, Visual Studio WinForms\/WPF Designers for .Net\u2026","rel":"","context":"In &quot;Android&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2228,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/2228\/","url_meta":{"origin":2433,"position":2},"title":"Come on Baby Light My Fire","date":"26 Jul 2014","format":false,"excerpt":"These are exciting times in the mobile development space, especially for followers of RemObjects work. Whilst the likes of Xamarin and Embarcadero pursue their cross-platform abstractions, with varying degrees of success, RemObjects have been focussing on delivering genuinely native solutions and the long term vision that underpins their compiler architecture\u2026","rel":"","context":"In &quot;Android&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":872,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/872\/","url_meta":{"origin":2433,"position":3},"title":"The Emperors New Native &#8211; pt. 2","date":"29 May 2012","format":false,"excerpt":"Marc Hoffman kindly took the time to respond to my previous post and prompted me to re-formulate and expand my observations on Jim McKeeths post (which never made it to the comments thread on the RO blog for reasons best known to The Cloud). The biggest issue I had with\u2026","rel":"","context":"In &quot;Delphi&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1910,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/1910\/","url_meta":{"origin":2433,"position":4},"title":"What&#8217;s In a Number .. ?","date":"16 Oct 2013","format":false,"excerpt":"Last week I picked up a Nokia 520 Windows Phone for what I consider to be an absolute bargain price (well under the NZ$299 RRP) specifically as a development handset to allow me to explore the Windows Phone support offered by Oxygene. I've only just started down this road but\u2026","rel":"","context":"In &quot;Delphi&quot;","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.deltics.co.nz\/blog\/wp-content\/uploads\/Screen-Shot-2013-10-15-at-14.38.41.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1514,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/1514\/","url_meta":{"origin":2433,"position":5},"title":"Exploding Some Delphi Pricing Myths","date":"27 Aug 2013","format":false,"excerpt":"More than one commenter to recent posts has trotted out the same tired old myths that, in their view, prevent [insert current owner of Delphi here] from being able to compete fairly on the pricing front. Some of these myths are as old as the Enterprise Customer thinking that is\u2026","rel":"","context":"In &quot;Delphi&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/2433"}],"collection":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/comments?post=2433"}],"version-history":[{"count":4,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/2433\/revisions"}],"predecessor-version":[{"id":2439,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/2433\/revisions\/2439"}],"wp:attachment":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/media?parent=2433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/categories?post=2433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/tags?post=2433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}