Dynamic const or not ?

In the IDE you can create constants.

And if you create them as string constants you can set them to be “localized” or not.

This gives you the ability to support multiple different languages in a single build as the localized language files will be saved and used by your application.

But what happens to other kinds of constants if you add different instance values to ? What does the IDE do with those ? And how does it use those ?

Create a new desktop project. Add a new number constant, kWindowMin. Then add set a new instance value for MacOS ANY LANGUAGE and make the value 500. Add another instance for Windows ANY LANGUAGE and make the value 700.

Set the Window1 Width to #kWindowMin

And notice what it does on macOS (or Windows) immediately. Then run it on macOS and Windows.

Note that this is NOT a value looked up at runtime. It’s not determined at runtime like a dynamic language constant is. With a dynamic constant you can change the system language, run and if there is a localization for that language it will show that localization. Stop the app, switch languages and run again and the new language should show.

This kind of constant is looked up in a platform specific way at COMPILE / BUILD time.

Its set AT COMPILE TIME and never again.

They can be handy because in some situations you need a larger window or field size because the default localized values for a language are longer (German tends to be this way compared to English)

And since you can use it for all kinds of values including integers yiu could use it for colors and have a different set of colors you use for macOS or Windows quite easily.

And you can use Booleans. So with settings for transparency its fairly easy to set up one value for macOS to be TRUE – since it supports transparency very nicely – and FALSE for Windows. Then you can assign that constant to those Windows & controls TRANSPARENT property and easily switch between macOS having transparency on and Windows having it off.

Enjoy !

4 Replies to “Dynamic const or not ?”

  1. Or set kWindowMin as a string constant and add different values for different languages and/or systems.

    In the window’s Open event do

    Me.Width = Val( kWindowMin )

    1. Yes you could use a string and make it change at runtime this way
      What you cant do is set the value in the inspector to the constant

  2. P.S. not sure I understand what is being said … maybe you could clarify it a bit?

    1. For the specific case of Transparent since Windows handles it less well than macOS its useful to define a boolean constant, kTransparent, with two values.
      For Windows define it as FALSE
      For MacOS define it as TRUE
      Then in the inspector set the TRANSPARENT property of every control to #kTransparent and then at compile time they correct transparency setting will be used based on which platform you’re compiling for

Comments are closed.