Xojo # constants

Is there documentation somewhere about things like
#strings. and #app.
Stuff that seems to get used in menus…
Is the # used here also a compiler directive?

While we’re talking about menus, what’s the difference between AppleMenuItem and ApplicationMenuItem? They both seem to add the menu item under the Application’s name.

It’s probably documented somewhere, but you’d likely have to specifically know what you’re looking for since there’s no longer a book-style manual.

The # symbol prefix on constants is only for use in the Interface Designer. This lets you use localized constants in the interface to localize your app. When using constants in code you don’t use the # symbol prefix.

AppleMenuItem is from classic Mac OS and should have been removed years and years ago. Something something not breaking existing projects, but holy crap it’s okay to update your code once in 20 years.

Thanks, @Tim!


Haven’t been able to find much, if anything on this topic. Would like to know more, especially about all the built-in constants that I see used in Xojo example menus.

It is probably buried in the user manual about localization
In many places in the IDE the # is required as a clue to the IDE that “this is the name of a constant NOT the literal string I want in here”
So you can use them just about anywhere a string literal could be used - not everywhere but most places

The examples are just ones that make it easy to have localized versions of menu items
Some are specifically set up to have something like “Options” instead of “Preferences” for user settings

Some are for things like “Quit” on macOS vs “Exit” on Windows

If you needed to cater to other languages then this is an easy way to do it since you can set a constant to be localized by OS AND language - SO in chinese on Windows you could have the proper chinse localization for “Exit” and one for Spanish on Windows and on macOS you’d have ot localized to say the correct term for Quit in Chinese or Spanish


Gotcha. Thanks, @npalardy!

A few of my posts that involve constants

Good stuff, @npalardy!
Odd that constants don’t have the same types as variables. e.g. “Number” instead of “Integer” or “Double”.

In the IDE the type is more or less implied since you could write

const foo = 90
cont bar = 9.0

IF you define them in code though you CAN also write

const foo as integer = 90
cont bar as double = 9.0

That just isnt available in the IDE inspector