#ifdef Statement

Delimit statements to be conditionally included in the build if a pre-processor symbol is defined.

Syntax

#ifdef [ symbol ]

[ statements1 ]

[ #else

[ statements2 ] ]

#endif

Comments

The statements allows the user to conditional build an application so that only the code relevant to the desired options is parsed. This can significantly reduce the size of the application as run and avoids problems such as unwanted code which uses a driver which will not available in the intended run environment.

If symbol is defined, the first block of statements will be parsed. If not, the first block of statements is skipped and the second block of statements is parsed. Either block of statements may be empty. If the second block of statements is empty, the #else statement can be omitted.

ATEasy is provided with pre-define pre-defined symbols. To define a user defined symbol, enter the symbol name in the Project Misc property page. If multiple symbols are required, separate them by commas.  

Example

The following example will include and compile block 1 of code if _MEZTRICS is define and block 3 if the code was compiled with ATEASY v5 or newer:

#ifdef _METRICS

! initialize scale factors for metric units, block 1

#else

! initialize scale factors for English unit, block 2

#endif

 

#ifdef ATEASY5

   ! bloack 3

cbCount.Anchor=actrlAnchorTop or actrlAnchorLeft or actrlAnchorRight

btnChangeCount.Anchor=actrlAnchorTop or actrlAnchorLeft or actrlAnchorRight

#else

   !block 4

cbCount.Move(x2,  cbCount.Top,  iAddButtonWidth, cbCount.Height)

btnChangeCount.Move(x2+(iGap/2),btnChangeCount.Top,iAddButtonWidth-iGap,btnChangeCount.Height)

#endif

See Also

#ifndef Statement, If statement , Preprocessor Symbols