Skip to content

Using Using

With Xojo 2015 Release 2, much of the new Xojo framework is now available for use in all project types. Because the new Xojo framework uses namespaces, you might want to take advantage of the Using command to help make your code easier to read and write.

But first, a brief aside about namespaces. The Xojo framework uses namespaces to provide better grouping of related features and to allow for classes with the same name to co-exist (Xojo.Core.Dictionary and Dictionary, for example). In fact, you can mix classic framework code and Xojo framework code together in the same method!

Typically to access a class without a namespace, you have to use the full name. So to access the Dictionary class in the Xojo framework, you would write:

Dim d As New Xojo.Core.Dictionary

But you don’t have to always include the “Xojo.Core” prefix if you don’t want to. At the top of a method you can add the Using statement to tell the compiler to automatically choose the members of the specified namespace. So you could write this:

Using Xojo.Core
Dim d As New Dictionary // uses Xojo.Core.Dictionary

You can also specify that an entire class or module choose the members in a namespace automatically. To do so, select the class in the Navigator and then select Insert -> Using Clause from the menu. This adds a “Using” clause to the Navigator and in the Inspector for it you can specify the namespace. When you do this, all the methods of the class automatically choose members from the namespace.

Keep in mind that you generally won’t have to worry about this for iOS projects, which by default let you refer to namespace members using just their name.