KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Pitfall in Compiler Compilation Path
PRODUCT: 4D | VERSION: 14.x | PLATFORM: Mac & Win
Published On: July 2, 2015

When setting the Database Settings for "Compilation Options" the best advice is to set "Compilation Path" to "All variables are typed." This is because there is no one that better knows the context of how a variable is to be used than the developer writing the code.

What a developer needs to be watchful for is depending or the "Default typing" of button, which 4D also considers variables, can create a runtime error condition uncaught by the compiler.

For example, consider Check boxes and Radio buttons variables on 4D forms. Without declaration by the developer their type will be set to either a Real or Long integer by the "Default typing". Check boxes and Radio buttons typically represent Boolean values, True or False. As a Real or Long integer their values will be set to 0 False or 1 for True.

When Check boxes and Radio buttons are tested they are normally tested for True or False, not 1 or 0. The conflict will not be presented as an error until the application is run as compiled. That is because when run as Interpreted 4D will change the typing from numeric to boolean. When compiled no change of type is done.

The lesson is that even form objects, especially Check boxes and Radio buttons, need to have compiler declarations to insure that they will be tested as intended once the application is run compiled.