Conditional importing of units

From Morfikwiki.com

Jump to: navigation, search

Contents

[edit] Introduction

Have you ever wanted to do a conditional import? That is, import different units based on a particular global variable?


[edit] Part 1

This is possible in Morfik Pascal as follows

INTERFACE

Uses
   Globals, MyModule1, MyModule2,

  {$IFDEF PROD}
    CreditsMYWSDL_Prod;
    {$ENDIF}

  {$IFDEF NOT PROD}
    CreditsMYWSDL_Dev;
    {$ENDIF}

IMPLEMENTATION

[edit] Part 2

To define the value of prod, use the syntax:

{$DEFINE PROD}

and

<{$UNDEF PROD} 

Note that this technique only works for parameters that are effectively equivalent to simple boolean types, where DEFINE sets it to TRUE, and UNDEF sets it to false.

Note again, that this is a compile-time concept and not a run-time concept. You will find this syntax throughout the Morfik framework where we do conditional defintions based on the which type of compiler is being used to compile your project.

For XApp developers, this design-time conditional compiling may be useful, for example, if you wish to be testing specific parts of the XApp code during a particular stage of the design process.

[edit] See also

[edit] External links

Personal tools