Summary:
See also: Classes and Objects
The Application class is a built-in class providing an interface to the application internals.
base.Application
Class Methods | |
Name | Description |
getArgumentCount() |
Returns the number of arguments passed to the program. |
getArgument( position INTEGER ) |
Returns the argument passed to the program, according to its position. |
getProgramName() |
Returns the name of the program. |
getProgramDir() |
Returns the system-dependent path of the directory where the program files are located. |
getFglDir() |
Returns the system-dependent path of the installation directory of the runtime system (FGLDIR environment variable). |
getResourceEntry( name STRING ) |
Returns the value of an FGLPROFILE entry. |
getStackTrace() |
Returns the current stack trace of the program flow. |
The Application class groups a set of utility functions related to the program environment. Command line arguments, execution directory and FGLPROFILE resource entries are some of the elements you can query with this class.
You can query command line arguments with the getArgumentCount()
and getArgument()
methods. The getArgumentCount()
method returns the total number of arguments passed to the program, while getArgument()
returns the argument value for the given position.
The first program argument is identified by the position 1. Argument number zero is the program name. If the argument position is negative or greater than getArgumentCount()
, the method returns NULL.
01
MAIN02
DEFINE i INTEGER03
FOR i=1 TO base.Application.getArgumentCount()04
DISPLAY base.Application.getArgument(i)05
END FOR06
END MAIN
Basic program execution information can be queried with the getProgramName()
and getProgramDir()
methods. The getProgramName()
method returns the name of the program. The getProgramDir()
method returns the directory path where the 42r program file is located. Note that the directory path is system-dependent.
Product information can be queried with the getFglDir()
method. The getFglDir()
method returns the installation directory path defined by FGLDIR. Note that the directory path is system-dependent.
If needed you can query FGLPROFILE resource entries with the getResourceEntry()
method. This method returns the fglprofile value of the entry passed as parameter.
01
MAIN02
DISPLAY base.Application.getResourceEntry("mycompany.params.logmode")03
END MAIN
In some situations - typically, to identify problems on a production site - you may want to known what functions have been called when a program raises an error. You can get and print the stack trace in a log file by using the getStackTrace()
method. This method returns a string containing a formatted list of the current function stack.
You typically use this function in a WHENEVER ERROR CALL handler, as in the following code example:
01
MAIN02
WHENEVER ERROR CALL my_handler03
...04
END MAIN05
...06
FUNCTION my_handler()07
DISPLAY base.Application.getStackTrace()08
END FUNCTION
Example of stack trace output:
#0 my_handler() at debug.4gl:173 #1 save_customer_data() at customer.4gl:1534 #2 edit_customer() at customer.4gl:542 #3 main at main.4gl:23