Skip to content

Compiler Improvements

We have improved the compiler error checking to report invalid "If" statement syntaxes.

DataFlex supports different methods of coding If statement evaluations. These are:

Type 1: If var ...... If (var) ......

If bOk ....
If (iError) ....

Type 2: If (var = Xxxx)

If (iValue = iOldValue) ....
If (iMode < eModeValue) ...

Type 3: If var eq Xxxx

If iValue eq iOldValue ....
If iMode ne eModeValue ...

When a number of new datatypes were added to VDF7 (e.g., datetime, short, currency), we declared that these types would not all work properly with Type 3 syntax. This is an old style of syntax usage that has been discouraged since VDF5. You were advised to use Type 1 or Type 2 syntax. If you used Type 3 syntax with certain data types, the program would compile, but it may not provide you with the evaluation you want. It also turns out that Type 1 syntax did not always work properly with some datatypes.

Example

DateTime dtVar
If (dtVar) .......

The above code will probably not work, nor does it make much sense as there is no way to know how to declare a datetime value as being false.

Beginning with DataFlex 8.3, all of these invalid datatype usages are reported at compile time. Now you get an error at compile time if you try to use Type 1 or Type 3 If syntaxes with the following variable types:

  • Float
  • Decimal
  • Currency
  • Time
  • DateTime
  • TimeSpan
  • Variant
  • BigInt
  • UBigInt
  • UInteger

The following data types may be used with all IF statements:

  • Real
  • Number
  • Date
  • String
  • Integer
  • Boolean
  • Short
  • UShort
  • Char
  • UChar
  • Address

The disallowed types can still be used, but they must be used properly within a boolean expression. For example:

Float fNumber
Move 0 to fNumber
If fNumber .... // This will generate a compiler error
If (fNumber) .... // This will generate a compiler error
If fNumber ne 0 .... // This will generate a compiler error
If (fNumber < 0) .... // This will work as expected. Use this!

You will spot any problems in your code when you compile your application. If you get a compiler error, the code is improper and must be changed. If the code was improper, it was not working properly with your previous DataFlex version; it just didn't tell you there was a problem. The improved compiler error checking will find these problems for you.

Although Type 3 syntax (e.g., If Var NE Xxxxx ....) is allowed for a number of datatypes, this usage is still considered obsolete and therefore not recommended.

In improving this error checking, we also discovered and fixed a bug with the Address datatype and IF statements. The following never worked properly:

if pData ...
if (pData) .....

Prior to this fix, you had to use the if (pData<>0) syntax. This has been fixed, and any of the above syntaxes now works properly.