« Dialogs with fields f… | Home | French Speaking FileM… »

Scopes and namespaces in Xojo

In Xojo we have several scopes for accessing properties or variables

  • Local variables within the method
  • Me to access properties in the current control (or class)
  • Self to access properties in the current window, web page or class
  • Module name to access properties in a module
  • App to access properties in the current application class, whatever it is named.
  • Global to access things in the global namespace with the same name as a local thing.
  • Xojo as the namespace that defines a lot of framework features.

The Xojo framework itself defines dozens of modules as namespaces. For example there is Xojo, System, Localization, Runtime, Introspection, Bitwise or Encodings to just name a few.

Me vs Self

The difference between me and self is, that me referes to a control while self refers to the window or webpage. In other cases they are the same, like in a subclass. We often use self or me to explicitly write into the code, that we refer to a property.

Global

The global keyword is an useful trick to keep in your mind. Whenever you need to access something in the global namespace, but you have something local with the same name. e.g.

Var Module1 As Integer
Module1 = global.Module1.insideModule1

Because we have a local variable Module1 that hides the module with the same name. To access the module, we have to use the global keyword.

Xojo Namespace

The Xojo namespace implemented as a module allows you to access framework features inside the namespace, even if the name is shadowed with a variable with the same name:

Var round As Integer
Round = xojo.Round(1)

In this example the name round is taken by the variable, so you can't simply call the round() function. You have to

26 02 26 - 13:30