As of FPC 2.3.1, the {$MODESWITCH} directive can be used to select some of the features that a
{$MODE } directive would select.
It can be used to enable language features that would otherwise not be available in the current
mode. For example, you might be programming in TP mode, but want to use the Out parameters,
which are only available in Delphi mode.
The {$MODESWITCH } directive enables or disables individual mode features without changing the
current compiler mode.
This switch is a global switch, and can be used wherever the {$MODE} switch can be
used.
The syntax is as follows:
{$MODESWITCH XXX}
{$MODESWITCH XXX+}
{$MODESWITCH XXX-}
The first two will switch on feature XXX, the last one will switch it off.
The feature XXX can be one of the following:
-
CLASS
- Use object pascal classes.
-
OBJPAS
- Automatically include the ObjPas unit.
-
RESULT
- Enable the Result identifier for function results.
-
PCHARTOSTRING
- Allow automatic conversion of null-terminated strings to strings,
-
CVAR
- Allow the use of the CVAR keyword.
-
NESTEDCOMMENTS
- Allow use of nested comments.
-
CLASSICPROCVARS
- Use classical procedural variables.
-
MACPROCVARS
- Use mac-style procedural variables.
-
REPEATFORWARD
- Implementation and Forward declaration must match completely.
-
POINTERTOPROCVAR
- Allow silent conversion of pointers to procedural variables.
-
AUTODEREF
- Automatic (silent) dereferencing of typed pointers.
-
INITFINAL
- Allow use of Initialization and Finalization
-
ANSISTRINGS
- Allow use of ansistrings.
-
OUT
- Allow use of the out parameter type.
-
DEFAULTPARAMETERS
- Allow use of default parameter values.
-
HINTDIRECTIVE
- Support the hint directives (deprecated, platform etc.)
-
DUPLICATELOCALS
- Allow local variables in class methods to have the same names as
properties of the class.
-
PROPERTIES
- Allow use of properties.
-
ALLOWINLINE
- Allow inline procedures.
-
EXCEPTIONS
- Allow the use of exceptions.
-
ADVANCEDRECORDS
- allow the use of advanced records (i.e. records with methods)
-
UNICODESTRINGS
- string is by default unicode string.
-
TYPEHELPERS
- Allow the use of type helpers.
-
CBLOCKS
- C style blocks.
-
ISOIO
- input/output as required by ISO pascal.
-
ISOPROGRAMPARAS
- Program parameters as required by ISO pascal.
-
ISOMOD
- mod operation as required by ISO pascal.
-
ISOUNARYMINUS
- Unary minus as required by ISO pascal.
Hence, the following:
{$MODE TP}
{$MODESWITCH OUT}
Will switch on the support for the out parameter type in TP mode. It is equivalent
to
{$MODE TP}
{$MODESWITCH OUT+}