Why implicit instance isnt your friend

When you start a new desktop project in Xojo you get a few items by default.

One of the is a Window – 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 Window Size Keep Changing and Enumerations act private when they are not

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.

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.

Enumerations are one that it definitely causes issues with. There may be others as I havent tested everything.

So, if you dont use implicit instance what DO you use ?

To create a new instance you use NEW. Just like you do with any other class.

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.

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 their own templates 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.

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 Overrides system. This makes it possible for you to make it so NO new windows added have implicit instance turned on.

One Reply to “Why implicit instance isnt your friend”

Comments are closed.