Unofficial Content
  • This documentation is valid for:

 

xx Murphy Law: every constant is not a constant, it change its value over time.  :)

Sometimes it's necessary to reference some literals or constants values in the code. For example it's very common to have the name and version of the system in the code, usually to display them in the top or bottom of a webpanel:

Event Start
     Name.Caption = "My Wonderful Application"
     Version.Caption = "1.0"
     ...
Endevent

The problem with this code is sometimes these values change, so you need to find where are this constant everywhere in the code. A better approach is to avoid the use of any literal in the code and concentrate all of them in a Domain. If all the parameters have the same type it can be implemented with an Enumerated Domain:

Event Start
   Name.Caption = SystemInfo.Name
   Version.Caption = SystemInfo.VersionNumber
   ...
Endevent

Domain: SystemInfo
Type: Char(30)
Enum Values:
Name "My Wonderful Application"
VersionNumber "1.0"

so, in this case, you just need to change the domain in case the constant change.

If the parameters have different types it can be implemented with the following code ( needs GX X Ev1 or above):

Domain: 
   SystemInfo based on SystemInfoSDT
   Initial Value: InitSystemInfo

SystemInfoSDT
{
   Name
   VersionNumber
}

InitSystemInfo   // Data Provider
{
   Name          = "My Wonderful Application"
   VersionNumber = '"1.0"
}

And the code to use it is:

Event Start
   Name.Caption = &SystemInfo.Name
   Version.Caption = &SystemInfo.VersionNumber
   ...
Endevent

See also System Parameters.

Example

The can3 constants are:

gxwiki constants

(I know, it should be named WikiConstants instead of WikiParameters, my fault :( jnj).

Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant