Summary:
See also: Built-in classes
The Application class is a built-in class providing an interface to the application internals.
base.Application
Class Methods | |
Name | Description |
getArgumentCount() RETURNING INTEGER |
Returns the number of arguments passed to the program. |
getArgument( position INTEGER ) RETURNING STRING |
Returns the argument passed to the program, according to its position. |
getProgramName() RETURNING STRING |
Returns the name of the program. |
getProgramDir() RETURNING STRING |
Returns the system-dependent path of the directory where the program files are located. |
getFglDir() RETURNING STRING |
Returns the system-dependent path of the installation directory of the runtime system (FGLDIR environment variable). |
getResourceEntry( name STRING ) RETURNING STRING |
Returns the value of an FGLPROFILE entry. |
getStackTrace() RETURNING STRING |
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. First argument starts at 1
(argument number zero is the program name).
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