{"id":667,"date":"2020-04-03T21:30:00","date_gmt":"2020-04-04T03:30:00","guid":{"rendered":"https:\/\/www.great-white-software.com\/blog\/?p=667"},"modified":"2020-03-28T21:53:02","modified_gmt":"2020-03-29T03:53:02","slug":"why-implicit-instance-isnt-your-friend","status":"publish","type":"post","link":"https:\/\/www.great-white-software.com\/blog\/2020\/04\/03\/why-implicit-instance-isnt-your-friend\/","title":{"rendered":"Why implicit instance isnt your friend"},"content":{"rendered":"\n<p>When you start a new desktop project in Xojo you get a few items by default. <\/p>\n\n\n\n<p>One of the is a Window &#8211; often named Window1.<\/p>\n\n\n\n<p>And it has a certain set of default properties. One of these causes a LOT of confusion and grief. You end up with issues like <a href=\"https:\/\/forum.xojo.com\/38072-window-opening-unexpectedly\">Window opening unexpectedly<\/a>, <a href=\"https:\/\/forum.xojo.com\/59094-mac-window-size-keeps-changing\">Mac Window Size Keep Changing<\/a> and <a href=\"http:\/\/feedback.xojo.com\/case\/59570\">Enumerations act private when they are not<\/a><\/p>\n\n\n\n<p>While at first implicit instance makes life simple once you get very far with Xojo it becomes a liability. It can be come an impediment to writing code.<\/p>\n\n\n\n<p>And the reason is that just by using the name of the window you actually run a method that will, if one doesnt already exist, create a new instance of the window. And this can block you from being able to access some things that are defined on that window.<\/p>\n\n\n\n<p>Enumerations are one that it definitely causes issues with. There may be others as I havent tested everything.<\/p>\n\n\n\n<p>So, if you dont use implicit instance what DO you use ?<\/p>\n\n\n\n<p>To create a new instance you use NEW. Just like you do with any other class. <\/p>\n\n\n\n<p>And if you dont want to create one IF one already exists then you can actually see if any other windows that are open ARE a Window1 and use that one.<\/p>\n\n\n\n<p>Implicit instance saves you writing about 10 lines of code. And causes even long time users no end of problems. In fact I know some users that have gone so far as to define <a href=\"http:\/\/docs.xojo.com\/UserGuide:Project_Types#Templates\">their own templates<\/a> for projects and have set the default Window1 to not have implicit instance on. But that only affects that first windows and any others inserted will still have it enabled.<\/p>\n\n\n\n<p>You can turn it off for ALL of the new ones you add to a projects by altering the default values for certain properties using the <a href=\"http:\/\/docs.xojo.com\/UserGuide:Overriding_System_Class_Defaults\">Overrides system<\/a>. This makes it possible for you to make it so NO new windows added have implicit instance turned on.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you start a new desktop project in Xojo you get a few items by default. One of the is a Window &#8211; often named Window1. And it has a certain set of default properties. One of these causes a LOT of confusion and grief. You end up with issues like Window opening unexpectedly, Mac &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.great-white-software.com\/blog\/2020\/04\/03\/why-implicit-instance-isnt-your-friend\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Why implicit instance isnt your friend&#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-667","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\/667","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=667"}],"version-history":[{"count":1,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/667\/revisions"}],"predecessor-version":[{"id":668,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/667\/revisions\/668"}],"wp:attachment":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/media?parent=667"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/categories?post=667"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/tags?post=667"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}