Wiki Home

VFP Compiler Directives


Namespace: VFP
A place to discuss compiler (preprocessor) directives.
Compiler directives are used to achieve conditional compilation. The compiler directives are:
  • #DEFINE ... #UNDEF - Creates and releases compile-time constants.
  • #DEFINE ... #UNDEF - Has anyone tried a compile-time constant to build a field list for SCATTER? VFP7.0 gives me a syntax error.
  • #DEFINE ... #UNDEF - Do not enclose the expression (field list) with quotation marks.
  • #IF expr ... #ENDIF - Conditionally includes source code at compile-time.
    expr must be a valid expression that either returns .T. or .F. Until version VFP 6/SP 3 an invalid expression causes an abnormal program termination (a so called GPF). expr can contain any Visual FoxPro function, including MESSAGEBOX() to display messages during compilation or STRTOFILE() to log certain events during compilation. However, it cannot contain a UDF.
    ALL #IF expressions are evaluated, regardless of nesting -- even when they are nested and the outer #IF evaluates to .F. In other words, nested #IFs don't behave like normal IF.

    From the MSDN Library Oct. 1999:
    #IF ... #ENDIF Preprocessor Directive
    Conditionally includes source code at compile-time.

    Syntax

    #IF nExpression1 | lExpression1
    Commands
    [#ELIF nExpression2 | #ELIF lExpression2
    Commands
    ...
    #ELIF nExpressionN | #ELIF lExpressionN
    Commands]
    [#ELSE
    Commands]
    #ENDIF
    HOWEVER, If my memory serves me correctly, in VFP 3.0 this same syntax was offered, but the #ELSE and (I think) the #ELIF did not work correctly... I haven't tested this recently, but am still in the habit of using two #IF .. #ENDIF statements instead of an #ELSE -- wgcs
  • #IFDEF | #IFNDEF ... #ENDIF - Conditionally includes a set of commands at compile time if a compile-time constant is defined (using #DEFINE)
    From the MSDN Library Oct. 1999, there is an optional #ELSE for the #IFDEF command:
    Syntax

    #IFDEF | #IFNDEF ConstantName
    Commands
    [#ELSE
    Commands]
    #ENDIF

    These # compiler directives (particularly #DEFINE'd compile-time constants) are typically placed in .H (Include Files) to make them more reuseable. #IFDEF and #IFNDEF in "normal" code can then refer to these compile-time constants.
    Contributors: Steven Black, Christof Wollenhaupt, David Frankenbach, wgcs
    Category Coding