{"id":692,"date":"2020-05-02T19:34:00","date_gmt":"2020-05-03T01:34:00","guid":{"rendered":"https:\/\/www.great-white-software.com\/blog\/?p=692"},"modified":"2020-04-16T20:20:43","modified_gmt":"2020-04-17T02:20:43","slug":"assigns","status":"publish","type":"post","link":"https:\/\/www.great-white-software.com\/blog\/2020\/05\/02\/assigns\/","title":{"rendered":"Assigns"},"content":{"rendered":"\n<p>Xojo has this great feature. You can write sets of methods that can act like LValues. That is &#8211; ones that can have a value assigned to them. Or ones that occur on the LEFT of an assignment operator.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dim i as integer\ni = 9 \/\/ &lt;&lt;&lt; i is an LValue<\/code><\/pre>\n\n\n\n<p>What can I do with assigns ?<\/p>\n\n\n\n<p>Well one of the things you can do is make methods behave like properties &#8211; regular or computed ones. So we can do something simple like<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Class myClass\n      Sub foo(assigns value as integer)\n        \/\/ now do whatever we want with value\n      End Sub\nEnd Class\n\ndim c as new myClass\nc.foo = 9<\/code><\/pre>\n\n\n\n<p>This is nice but you can get the exact same effect with a public property or a computed property. So no real big deal here. You could have<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Class myClass\n     Public foo as integer\nEnd Class\n\ndim c as new myClass\nc.foo = 9<\/code><\/pre>\n\n\n\n<p>OR something like<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Class myClass\n      ComputedProperty foo\n        \/\/ now do whatever we want with value\n      End ComputedProperty\nEnd Class\n\ndim c as new myClass\nc.foo = 9<\/code><\/pre>\n\n\n\n<p>You really cant tell which form was used. And thats actually a nice trick that not many other languages have.<\/p>\n\n\n\n<p>But, since we can write ANY kind of method that uses Assigns as the last parameter we can do things that are not possible with public properties or computed properties.<\/p>\n\n\n\n<p>So we could write a method that, given an integer and string key gets assigned a value that gets stored in a database.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Sub newPrice(partID as integer, partName as string, assigns newPrice as double)<\/code><\/pre>\n\n\n\n<p>and then use this elsewhere like<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>newPrice(123, \"washer\") = 49.95<\/code><\/pre>\n\n\n\n<p>Public properties and computed properties are usually where I start when writing code, and I&#8217;ll transition from a public property to a computed one and then to a get \/ set pair of methods as needs are revised.<\/p>\n\n\n\n<p>Fortunately Xojo makes this transition easy because each of those can be swapped for the other without any impact on the rest of your code when they have the same signature. FOr instance, without examining the code you have no idea whether the following uses a public property, computed property, or setter method with assigns<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dim c as new myClass\nc.someProperty = 100<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Xojo has this great feature. You can write sets of methods that can act like LValues. That is &#8211; ones that can have a value assigned to them. Or ones that occur on the LEFT of an assignment operator. What can I do with assigns ? Well one of the things you can do is &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.great-white-software.com\/blog\/2020\/05\/02\/assigns\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Assigns&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-692","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/692","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/comments?post=692"}],"version-history":[{"count":2,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/692\/revisions"}],"predecessor-version":[{"id":709,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/692\/revisions\/709"}],"wp:attachment":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/media?parent=692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/categories?post=692"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/tags?post=692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}