Compiler Directives
From RemObjects Software
This is a Oxygene Language Feature topic
Feel free to add your notes to this topic below.
Overflow Checking
The $OVERFLOW or $Q directive controls how Overflow Checking will be applied to all following code.
Use of the DEFAULT setting will revert to the default overflow option configured by the project (usually OFF). This is useful for wrapping a section of code in a specific Overflow model, without affecting the rest of the source file, by wrapping it in {$OVERFLOW OFF}...{$OFERFLOW DEFAULT}
- $OVERFLOW ON/OFF/DEFAULT
- $Q+, $Q- — provided for Delphi compatibility
Controlling Compiler Messages
The $SHOW and $HIDE directives can be used to explicitly suppress or unsuppress a given compiler Hint or Warning. For example {$HIDE PW12, commonly found in auto-generated code from CodeDom, will stop the "Variable X might hide existing variable X" warning.
For obvious reasons only Hints and Warnings can be hidden, no Errors. If the Treat Warnings as Errors option is enabled, warnings that are hidden by use of $HIDE will not be handled as errors.
- $SHOW <Message ID>
- $HIDE <Message ID>
- $SHOWMESSAGE <Message ID>
- $HIDEMESSAGE <Message ID>
The long version, $SHOWMESSAGE and $HIDEMESSAGE, are provided for backward compatibility, and work identically to $SHOW and $HIDE, respectively
Emiting Your Own Compiler Messages
In addition to controlling what compiler messages are emitted, Oxygene also enables you to emit custom error and warning messages from your code, using the following four directives. This is useful, for example to mark conditionally compiled code that has not been implemented for all conditional cases, such as {$IFDEF COMPACTFRAMEWORK}{$ERROR Not Implemented for the CF yet.}{$ENDIF}.
No quotes are required around the message text, but if a set of matching quotes is found, it will be stripped from the emitted message, for backward compatibility.
The first three directives are provided to emit messages corresponding to compiler Errors, Warnings and Hints. Similar to compiler-generated messages, Errors (and, if the Treat Warnings as Errors option is enabled, warnings) will fail the compile process, while the others are purely informational messages.
When using these directives, it is recommended to pick the appropriate type that matches the severity of the message, with Errors representing an unrecoverable problem, Warnings indicating a likely unexpected misbehavior and Hints merely providing optimization-type info that does not affect the code's execution.
- $WARNING <Message>
- $ERROR <Message>
- $HINT <Message>
- $MESSAGE <Message>
Conditional Compilation
(TODO: add description)
- $DEFINE
- $UNDEF
- $IFDEF
- $IFOPT
- $IFNDEF
- $ENDIF
- $ELSE
Other Directives
The $INCLUDE (or $I) directive includes the content of the specified file, as if it were written inline at the position of the directive. The file specified in the $INCLUDE directive needs to have a .inc extension, and be included in the project (the compiler will not compile .inc files in the project directly).
- $INCLUDE filename
- $I filename
The $LINE directive is provided for use by auto-generated code such as from ASP.NET, and should not normally be used in hand-written code. The directive can be used to map compiler messages such as warnings and errors to different files and line numbers. For example, in ASP.NET it is used to have errors that occur in Oxygene source files auto-generated behind the scenes reflected in the appropriate lines of the .ASPX file, instead.
- $LINE #/HIDDEN/DEFAULT
The $PARAMETER directive can be used to inject strings and code elements into source code, from the command line build. This is helpful, for example, to insert specific assembly version numbers into strings used in design-time attributes.
For example, you could call the command line compiler using oxygene.exe -params:Version=1.0.3.389 and use the following in your code [SomeDesignTimeAttribute('DesignerType, Designer.Assembly, Version='+{$PARAMETER Version}+'...')]
- $PARAMETER string
Ignored Directives
While unknown directives found in code will generate compiler errors, the following directives will be actively ignored by the compiler:
- $REGION / $ENDREGION — used for Code Folding in editor only
- $HPPEMIT — provided for Delphi compatibility
- $EXTERNALSYM — provided for Delphi compatibility
Product: RemObjects Oxygene (formerly known as Chrome)
Current version: 3.0
Previous Versions: 'Joyride' (2.0), 'Floorshow' (1.5), 'Adrenochrome' (1.0)
Glossary — Keywords — Language Features — Platform Features — Samples — Articles — How To — Issues
Categories: Text | Oxygene | Feature
