Share via


Strong Typing in Class, Objects, and Variable code

Visual FoxPro is not a strongly typed language in which you must declare variables as a specific data type. However, strong typing provides control that makes coding easier and less error-prone, and supports IntelliSense for these items in the editor.

Note   Strong typing is not enforced at design time or at run time. In Visual FoxPro, strong typing allows IntelliSense objects in the editor. Strong typing also is used in OLEPUBLIC type libraries.

To implement strong typing, use the AS clause in LPARAMETERS Command, PARAMETERS Command, LOCAL Command, and PUBLIC Command parameter and variable declarations, as well as FUNCTION Command and PROCEDURE Command statements as in the following examples:

LOCAL oExcel AS "excel.application"
oExcel = CreateObject("excel.application")
oExcel.   &&displays dropdown

PUBLIC ARRAY MyArray[2] AS _form OF ffc\_base

LPARAMETERS MyParam1 AS string OF _base.vcx

PARAMETERS MyParam1 AS custom OF Mybase.vcx

FUNCTION MyFunction AS custom

You can also use the AS clause in the DEFINE CLASS Command command to apply strong typing to objects, method parameters, and values.

DEFINE CLASS MyClass1 AS custom OLEPUBLIC
   FUNCTION MyMethod (MyParam1 AS integer, MyParam2 AS string) AS integer
      RETURN MyParam1 
   ENDFUNCTION
ENDDEFINE

See Also

IntelliSense Overview | Auto MRU (Most Recently Used) Files