Program(), Sys(16), AStackInfo()
These functions tell you about the program currently executing and the execution chain. They're especially handy when you're debugging.
Usage |
nProgDepth = PROGRAM( -1 ) cProgInChain = PROGRAM( [ nLevel ] ) cProgInChain = SYS( 16 [ , nLevel ] ) |
SYS(16, 1) is the key to finding out how you got started. It returns the name of the APP or EXE file that was run (assuming that's how you ran the application). This is especially important when working with apps that have a form marked as main—in that case, the file portion of SYS(16) indicates the SCT, not the APP or EXE. |
lcDir = JustPath(SYS(16)) && Or in VFP 5 and before, lcDir = LEFT(SYS(16), AT('\', SYS(16))) USE (lcDir + 'MYTABLE')The example below is a function that traces the entire execution chain and fills an array with the results. In VFP 6 and earlier versions, you might call this function from an error handler to determine what was going on when the program failed. In VFP 7, you don't need this function; use ASTACKINFO(), instead.
Example |
* AProgram.PRG * Fill an array with the programs in use, except this one. * Column 1 contains the program name returned by PROGRAM(). * Column 2 contains the detailed information returned by * SYS(16). * Return the size of the array. * If parameter isn't an array, return -1. LPARAMETERS aProgs * Check parameter IF TYPE("aProgs[1]")="U" RETURN -1 ENDIF * Trace the calling chain. LOCAL nLevel FOR nLevel = 1 TO PROGRAM(-1) DIMENSION aProgs[nLevel,2] aProgs[nLevel,1] = PROGRAM(nLevel) aProgs[nLevel,2] = SYS(16,nLevel) ENDFOR * Now remove last row which represents this program. DIMENSION aProgs[nLevel-2,2] RETURN nLevel-2 |
Usage |
nLevels = ASTACKINFO( aProgChain ) |
Column |
Contents |
1 |
The stack level. |
2 |
The name of the file executing at this level. |
3 |
The name of the module or object executing at this level. |
4 |
The name of the source code file for the code executing at this level. |
5 |
The line number executing at this level. |
6 |
The line of code executing at this level. |
When you're running an APP or EXE, the second column of the array should contain the name of the APP or EXE in every row. When you call AStackInfo() from a form or class, the second column contains the name of the SCT or VCT, instead. |
See Also |