Sw4   >   Misc   >   Miscellaneous


This is the catchall section for topics that don't warrant a separate category.


The oConstants object class is used to store any constant values which you want available to all of the class instances in your application. The oConstants object is instantiated using the startup task variable cn.

Property methods can be used to get and set constant values.

; Set the app mode.
Do cn.$:AppMode.$assign('web')

; Get the app mode.
Do cn.$:AppMode() Returns AppMode

To add your own constant to oConstants do the following:

  1. Subclass swBase4.oConstants to your main library, if this isn't already done.
  2. Point your main library startup task variable cn to oConstants in your main library.
  3. Copy the schema class swBase4.sConstants_listdef to your main library.
  4. Add a new column to sConstants_listdef in your main library. The column name will be used as the property method name. It is recommended that you use all lower case characters to stick with the StudioWorks _listdef naming convention.
  5. Right-click the main library Startup_Task. Close and then reopen the startup task.

    When the oConstants object is initialized during startup it will automatically add the getter and setter property methods to the oConstants object in your main library. You can then rename the method names to mixed case names for better readability. The new getter and setter property methods are available throughout your application.

You have the option of setting any of the oConstants property values from the startupsettings.txt file.

  1. Add a constants group to the APP/startupitems/startupsettings.txt.
  2. Add a propery and value for each constant you want to set from the startup settings files.

    constants {
        appmode = 'web' ;


    Always remember to include the ; delimiter after each property. The property names are case insensitive.

    During startup the swBase4.oStartupTaskVarTool.$init_cn method loops through the constants group of the startupsettings file and set the values in oConstants. An error will be logged if the $assign setter method is not found in oConstants.