{"id":311,"date":"2019-09-18T06:43:58","date_gmt":"2019-09-18T12:43:58","guid":{"rendered":"https:\/\/www.great-white-software.com\/blog\/?p=311"},"modified":"2019-09-19T14:02:24","modified_gmt":"2019-09-19T20:02:24","slug":"debugging-tip","status":"publish","type":"post","link":"https:\/\/www.great-white-software.com\/blog\/2019\/09\/18\/debugging-tip\/","title":{"rendered":"Debugging tip"},"content":{"rendered":"\n<p>Sometime when you&#8217;re debugging your application you run into a situation where you get funky behaviour. <\/p>\n\n\n\n<p>You might do something like Javier mentioned in his recent blog post on Xojo&#8217;s blog :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Dim ASource() As Integer = Array(1,2,3,4,5,6,7,8)\nDim ATarget() As Integer\nATarget = ASource<\/code><\/pre>\n\n\n\n<p>And, as he noted, you cant figure out why when you change one array you also appear to alter the other. This can also happen with other <a href=\"https:\/\/www.great-white-software.com\/blog\/2019\/05\/28\/follow-up-on-what-type-am-i\/\">reference types<\/a> as I noted in other posts.<\/p>\n\n\n\n<p>For instance I&#8217;ve seen<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Dim d As New Date\nDim d1 As date\nd1 = d\n\nd1.month = 2<\/code><\/pre>\n\n\n\n<p>and then the question of &#8220;why did d change?&#8221; arises<\/p>\n\n\n\n<p>Again this has been covered before and it has to do with both arrays and dates, as well as many other type, being reference types.<\/p>\n\n\n\n<p>One way to see that in fact these are the same object is not well documented in the Xojo documentation. Its buried in the Debugging pane of the preferences &#8211; Show Object IDs in variable lists.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1451\" height=\"907\" src=\"https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2019\/09\/Screen-Shot-2019-09-18-at-6.29.48-AM.png?fit=840%2C525&amp;ssl=1\" alt=\"\" class=\"wp-image-312\" srcset=\"https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2019\/09\/Screen-Shot-2019-09-18-at-6.29.48-AM.png?w=1451&amp;ssl=1 1451w, https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2019\/09\/Screen-Shot-2019-09-18-at-6.29.48-AM.png?resize=300%2C188&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2019\/09\/Screen-Shot-2019-09-18-at-6.29.48-AM.png?resize=768%2C480&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2019\/09\/Screen-Shot-2019-09-18-at-6.29.48-AM.png?resize=1024%2C640&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2019\/09\/Screen-Shot-2019-09-18-at-6.29.48-AM.png?resize=1200%2C750&amp;ssl=1 1200w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<p>Once you enable this setting what you see in the debugger pane makes it much easier to see when you have two references to the same object.<\/p>\n\n\n\n<p>When viewing the following code<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Dim ASource() As Integer = Array(1,2,3,4,5,6,7,8)\nDim ATarget() As Integer\nATarget = ASource<\/code><\/pre>\n\n\n\n<p>You can clearly see that ATarget and ASource have the same objectID. In Xojo&#8217;s runtime this means they are the same object &#8211; objectsID&#8217;s are unique to every instance and the only way you get two objectID&#8217;s that are the same is when two references refer to the same object.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"525\" height=\"230\" src=\"https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2019\/09\/Screen-Shot-2019-09-19-at-2.00.45-PM.png?resize=525%2C230&#038;ssl=1\" alt=\"\" class=\"wp-image-318\" srcset=\"https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2019\/09\/Screen-Shot-2019-09-19-at-2.00.45-PM.png?w=546&amp;ssl=1 546w, https:\/\/i0.wp.com\/www.great-white-software.com\/blog\/wp-content\/uploads\/2019\/09\/Screen-Shot-2019-09-19-at-2.00.45-PM.png?resize=300%2C131&amp;ssl=1 300w\" sizes=\"auto, (max-width: 525px) 100vw, 525px\" \/><\/figure>\n\n\n\n<p>I&#8217;d recommend always turning this setting on when debugging.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometime when you&#8217;re debugging your application you run into a situation where you get funky behaviour. You might do something like Javier mentioned in his recent blog post on Xojo&#8217;s blog : And, as he noted, you cant figure out why when you change one array you also appear to alter the other. This can &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.great-white-software.com\/blog\/2019\/09\/18\/debugging-tip\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Debugging tip&#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":[18,6,3],"class_list":["post-311","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-debugging","tag-tips","tag-xojo"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/311","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=311"}],"version-history":[{"count":5,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/311\/revisions"}],"predecessor-version":[{"id":320,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/311\/revisions\/320"}],"wp:attachment":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/media?parent=311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/categories?post=311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/tags?post=311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}