Tracking Undeclared Variables with FoxPro
Well let’s start by showing you how to track those undeclared variables in a FoxPro application, as we all know that we don’t have to declare a variable before use in this wonderful language, but it is good practice to do so.
So today I found the exact use of the ‘_VFP.LanguageOptions’ Property so let me share what I found. Well I new this existed since Version 7 but never investigated its use till today.
I have a small application that is been developed in my spare time, this program is what I will use to locate the undeclared variables on.
So let’s start:
All this is done in the VFP Command window
_VFP.LanguageOptions = 1
SET DEBUGOUT TO C:\Temp\UnDeclared.txt
DO Rebuild.exe
SET DEBUGOUT TO
To let you know, I went through all the options in my application, making sure I opened all the forms within the app, and then clicked the exit button to return back to the VFP command window.
So I opened the Undeclared.txt file and found the following:
LangOptionsErr,29/04/2005 11:18:03,122,CLSINITOOBJECT.GETDATA,PROCEDURE CLSINITOOBJECT.GETDATA INITOOBJ.FXP,LAINIFILE
LangOptionsErr,29/04/2005 11:18:03,168,CLSINITOOBJECT.GETDATA,PROCEDURE CLSINITOOBJECT.GETDATA INITOOBJ.FXP,LCREALNAME
LangOptionsErr,29/04/2005 11:18:03,83,CLSREBUILD.SETENVIRONMENT,PROCEDURE CLSREBUILD.SETENVIRONMENT E:\DEVELOPMENT\VFP\REINDEX\REBUILD.EXE,LADIRS
LangOptionsErr,29/04/2005 11:18:03,5,FRMREBUILD.ADDTOLIST,PROCEDURE FRMREBUILD.ADDTOLIST E:\DEVELOPMENT\VFP\REINDEX\SOURCE\FORMS\FRMREBUILD.SCT,LADIRS
LangOptionsErr,29/04/2005 11:18:07,8,FRMPROPS.BUILDDIRECTORYLIST,PROCEDURE FRMPROPS.BUILDDIRECTORYLIST E:\DEVELOPMENT\VFP\REINDEX\SOURCE\FORMS\FRMPROPS.SCT,LADIRS
LangOptionsErr,29/04/2005 11:18:07,11,FRMPROPS.BUILDDIRECTORYLIST,PROCEDURE FRMPROPS.BUILDDIRECTORYLIST E:\DEVELOPMENT\VFP\REINDEX\SOURCE\FORMS\FRMPROPS.SCT,LADBC
LangOptionsErr,29/04/2005 11:18:07,12,FRMPROPS.BUILDDIRECTORYLIST,PROCEDURE FRMPROPS.BUILDDIRECTORYLIST E:\DEVELOPMENT\VFP\REINDEX\SOURCE\FORMS\FRMPROPS.SCT,LADBF
LangOptionsErr,29/04/2005 11:18:19,5,FRMREBUILD.ADDTOLIST,PROCEDURE FRMREBUILD.ADDTOLIST E:\DEVELOPMENT\VFP\REINDEX\SOURCE\FORMS\FRMREBUILD.SCT,LADIRS
So what does this mean I hear you cry well lets break down the columns:
|
LangOptionsErr |
Specifies the name of the output type for searches and filters |
|
DateTime |
Specifies the time stamp when run (= DATETIME( )) |
|
cLineNo |
Specifies the line number where error occurred (=LINENO( )) |
|
cProcedure|cMethod |
Specifies the name of the procedure or method in which the error occurred ( = PROGRAM( )) |
|
cFileName |
Specifies the name of the file in which the error occurred. (=SYS(16( )) |
|
cVarName |
Specifies the name of the undeclared variable |
So using this information, you can see that in the INIToObj.Prg in the Class GetData Method I have two variables that are not declared with a LOCAL or PUBLIC. These are: laINIFile and lcRealName
Likewise you can see the other forms that have undeclared variables.
Main reason behind these arrays are the fact they are created with the ALINES function, this creates the variables as PRIVATE.
(Taken from VFP Help file)
Declaring variables PRIVATE does not create a variable (unlike declaring variables PUBLIC or LOCAL).
Commands that create variables on the fly, such as SCATTER ... NAME, REPORT ... NAME and others, will generate log entries, because these variables are created as PRIVATE.