Global- or App-Property?


I’m using some properties which i need in many methods of my app. So i startet to create a global Module called Globals where i placed this properties and some methods like connecting to database which i need all over in my app.

In the meantime, I also placed some propertiers in the app-properties like my app-settings coming from a json-file. To me they are as “global” as the properties in the Globals module. I can use them in every method of my app when adding a “app.” in front of the needed property.

My question is what is the difference using this two ways and what is the best way to do it?

Hope you get what i mean.


Modules can be easily copied between projects or even made external, so are ideal for general methods.

For example I have the following modules in all my apps


Think of modules as a way to structure your project into reusable parts.

Only put into app what is specific to the app.

globals in a module are much faster than accessing anything on app object.

Ok, nearly all of my global used properties are app-specific. Should i place them in the app-properties (slower, like Christian said)?

Only the db-poperties and -methods are universal and maybe used in an other app in the future so thy would fulfill the conditions of an module like Markus said.

Make a separate module for them as they aren’t “transportable”

Just because you won’t need to reuse them in another project doesn’t mean you have to put them in the App object. Especially if it will be slower (that one I did not know before!)

I would say use modules because it’s easier to maintain, you’ll remember where you put the properties a few months down the road.

@Christian:: what’s the reason that Modules are faster? I didn’t know that either.

If you don’t need to access the modules thousands of times I doubt it will make any difference.

I would create an app subclass names “mymadeapp”, and then make App a subclass of this mymadeapp class
all properties goes in that mymadeapp
for all other apps you make, only tell them a subclass of mymadeapp

I have two of them : an app subclass and a module named “myappglobals” for each app
everything that is specific to the app is in the app class or the myappglobals module
everything that can be reused is in “mymadeapp” class

don’t you guys read my block. It was a topic there:

and here:

and Feedback case 16764.

The difference is that for shared property on app or a property in module, no code is executed. But using app instance properties need to call GetAppObject which is slow. I never understood why Xojo can’t make App a global property set at app startup. Cocoa framework also has a NSApp variable to reference NSApplication.

Thanks you all for your tipps and recommendations. I now have made different modules for special purpose like DBModule, UserModule, PrefsModule and an AppModule which takes the rest. All the properties from the app-properties are now distributed to one of these modules.



I do read your blog religiously, alas my memory is even worse than my comprehension;-)

That’s because users can rename the App class. If we didn’t allow that, it’d be really easy to find.


Does this mean we SHOULD rename app?

you can rename app class. But why couldn’t you internally just put it in a global variable and have GetAppObject function return that reference?
So application class constructor set global App variable and app function returns that, independent of the name.