Delphi XE2's hidden hints and warnings options
There are a number of warnings available in Delphi XE2 that are not very well documented. While you can control them in the Project options dialog, and you can turn them on using {$WARN} directives or in command line compiler options, the documentation for the warning identifiers is currently pretty piecemeal, and there is no clear link between the project options, warning directive identifiers, and numeric identifiers.
The {$WARN} compiler directive takes effect only in the unit it is in. It overrides project settings and command line compiler flags. To turn a warning on or off for a block of code (although you'll have to work hard to convince me that this is an acceptable solution 99% of the time):
The {$WARN} compiler directive takes effect only in the unit it is in. It overrides project settings and command line compiler flags. To turn a warning on or off for a block of code (although you'll have to work hard to convince me that this is an acceptable solution 99% of the time):
To restore the warning to its previous setting:{$WARN SYMBOL_DEPRECATED ON}{$WARN SYMBOL_DEPRECATED OFF}
And finally, you can convert a warning into an error:{$WARN SYMBOL_DEPRECATED DEFAULT}
To change the setting in your project, go to Project|Options, Delphi Compiler, Hints and Warnings, and expand the Output warnings setting:{$WARN SYMBOL_DEPRECATED ERROR}
![]() |
Delphi's project options dialog - hints and warnings |
To change the setting in the command line compiler, use the -W flag, for example:
Or to turn the warning into an error:dcc32 -W+SYMBOL_DEPRECATED myproject.dpr
dcc32 -W-SYMBOL_DEPRECATED myproject.dpr
Note, if you type this from the Windows command prompt, you will have to repeat the ^ symbol, as ^ is an escape symbol:dcc32 -W^SYMBOL_DEPRECATED myproject.dpr
dcc32 -W^^SYMBOL_DEPRECATED myproject.dprThese are the hints and warning identifiers I am aware, along with what I understand are the default settings and numeric identifiers, and links to the relevant help topics.
ID | Directive ID | Default | Description | Notes |
---|---|---|---|---|
W1000 | SYMBOL_DEPRECATED | OFF | Symbol '%s' is deprecated (Delphi) | |
W1001 | SYMBOL_LIBRARY | OFF | Symbol '%s' is specific to a library (Delphi) | |
W1002 | SYMBOL_PLATFORM | OFF | Symbol '%s' is specific to a platform (Delphi) | |
W1003 | SYMBOL_EXPERIMENTAL | ON | Symbol '%s' is experimental (Delphi) | |
W1004 | UNIT_LIBRARY | OFF | Unit '%s' is specific to a library (Delphi) | |
W1005 | UNIT_PLATFORM | OFF | Unit '%s' is specific to a platform (Delphi) | |
W1006 | UNIT_DEPRECATED | OFF | Unit '%s' is deprecated (Delphi) | |
W1007 | UNIT_EXPERIMENTAL | ON | Unit '%s' is experimental (Delphi) | |
W1008 | HRESULT_COMPAT | ON | Integer and HRESULT interchanged | |
W1009 | HIDING_MEMBER | ON | Redeclaration of '%s' hides a member in the base class (Delphi) | |
W1010 | HIDDEN_VIRTUAL | ON | Method '%s' hides virtual method of base type '%s' (Delphi) | |
W1011 | GARBAGE | ON | Text after final 'END.' - ignored by compiler (Delphi) | |
W1012 | BOUNDS_ERROR | ON | Constant expression violates subrange bounds | |
W1013 | ZERO_NIL_COMPAT | ON | Constant 0 converted to NIL (Delphi) | |
W1014 | STRING_CONST_TRUNCED | ON | String constant truncated to fit STRING%ld (Delphi) | |
W1015 | FOR_LOOP_VAR_VARPAR | ON | FOR-Loop variable '%s' cannot be passed as var parameter (Delphi) | |
W1016 | TYPED_CONST_VARPAR | ON | Typed constant '%s' passed as var parameter (Delphi) | |
W1017 | ASG_TO_TYPED_CONST | ON | Assignment to typed constant '%s' (Delphi) | |
W1018 | CASE_LABEL_RANGE | ON | Case label outside of range of case expression (Delphi) | |
x1019 | FOR_VARIABLE | ON | For loop control variable must be simple local variable (Delphi) | |
x1020 | CONSTRUCTING_ABSTRACT | ON | Constructing instance of '%s' containing abstract method '%s.%s' (Delphi) | |
W1021 | COMPARISON_FALSE | ON | Comparison always evaluates to False (Delphi) | |
W1022 | COMPARISON_TRUE | ON | Comparison always evaluates to True (Delphi) | |
W1023 | COMPARING_SIGNED_UNSIGNED | ON | Comparing signed and unsigned types - widened both operands (Delphi) | |
W1024 | COMBINING_SIGNED_UNSIGNED | ON | Combining signed and unsigned types - widened both operands (Delphi) | |
x1025 | UNSUPPORTED_CONSTRUCT | ON | Unsupported language feature: '%s' (Delphi) | |
x1026 | FILE_OPEN | ON | File not found '%s' (Delphi) | Despite being listed as a warning, turning this off appears to have no effect. |
F1027 | FILE_OPEN_UNITSRC | ON | Unit not found '%s' or binary equivalents (%s) (Delphi) | |
x1028 | BAD_GLOBAL_SYMBOL | ON | Bad global symbol definition '%s' in object file '%s' (Delphi) | |
W1029 | DUPLICATE_CTOR_DTOR | ON | Duplicate %s '%s' with identical parameters will be inacessible from C++ (Delphi) | |
x1030 | INVALID_DIRECTIVE | ON | Invalid compiler directive - '%s' (Delphi) | |
W1031 | PACKAGE_NO_LINK | ON | Package '%s' will not be written to disk because -J option is enabled (Delphi) | |
W1032 | PACKAGED_THREADVAR | ON | Exported package threadvar '%s.%s' cannot be used outside of this package (Delphi) | |
W1033 | IMPLICIT_IMPORT | ON | Unit '%s' implicitly imported into package '%s' (Delphi) | |
W1034 | HPPEMIT_IGNORED | ON | $HPPEMIT '%s' ignored (Delphi) | |
W1035 | NO_RETVAL | ON | Return value of function '%s' might be undefined (Delphi) | |
W1036 | USE_BEFORE_DEF | ON | Variable '%s' might not have been initialized (Delphi) | |
W1037 | FOR_LOOP_VAR_UNDEF | ON | FOR-Loop variable '%s' may be undefined after loop (Delphi) | |
E1038 | UNIT_NAME_MISMATCH | ON | Unit identifier '%s' does not match file name (Delphi) | |
W1039 | NO_CFG_FILE_FOUND | ON | No configuration files found (Delphi) | |
W1040 | IMPLICIT_VARIANTS | ON | Implicit use of Variants unit (Delphi) | |
W1041 | UNICODE_TO_LOCALE | ON | Error converting Unicode char to locale charset. String truncated. Is your LANG environment variable set correctly (Delphi) | |
W1042 | LOCALE_TO_UNICODE | ON | Error converting locale string '%s' to Unicode. String truncated. Is your LANG environment variable set correctly (Delphi) | |
W1043 | IMAGEBASE_MULTIPLE | ON | Imagebase $%X is not a multiple of 64k. Rounding down to $%X (Delphi) | |
W1044 | SUSPICIOUS_TYPECAST | ON | Suspicious typecast of %s to %s (Delphi) | |
W1045 | PRIVATE_PROPACCESSOR | ON | Property declaration references ancestor private '%s.%s' (Delphi) | |
W1046 | UNSAFE_TYPE | OFF | Unsafe type '%s%s%s' (Delphi) | |
W1047 | UNSAFE_CODE | OFF | Unsafe code '%s' (Delphi) | |
W1048 | UNSAFE_CAST | OFF | Unsafe typecast of '%s' to '%s' (Delphi) | |
W1049 | OPTION_TRUNCATED | ON | value '%s' for option %s was truncated (Delphi) | |
W1050 | WIDECHAR_REDUCED | ON | WideChar reduced to byte char in set expressions (Delphi) | |
W1051 | DUPLICATES_IGNORED | ON | Duplicate symbol names in namespace. Using '%s.%s' found in %s. Ignoring duplicate in %s (Delphi) | |
W1052 | UNIT_INIT_SEQ | ON | Can't find System.Runtime.CompilerServices.RunClassConstructor. Unit initialization order will not follow uses clause order | Does not seem to be documented in XE2 |
W1053 | LOCAL_PINVOKE | ON | Local PInvoke code has not been made because external routine '%s' in package '%s' is defined using package local types in its custom attributes | Does not seem to be documented in XE2 |
x1054 | MESSAGE_DIRECTIVE | ON | %s (Delphi) | User-defined warning messages (see below). Turns off message hints as well but not message errors. |
W1055 | TYPEINFO_IMPLICITLY_ADDED | ON | Published caused RTTI ($M+) to be added to type '%s' (Delphi) | |
x1056 | RLINK_WARNING | ON | Duplicate resource Type %s, ID %s; File %s resource kept; file %s resource discarded (Delphi) | |
W1057 | IMPLICIT_STRING_CAST | ON | Implicit string cast from '%s' to '%s' (Delphi) | |
W1058 | IMPLICIT_STRING_CAST_LOSS | ON | Implicit string cast with potential data loss from '%s' to '%s' (Delphi) | |
W1059 | EXPLICIT_STRING_CAST | OFF | Explicit string cast from '%s' to '%s' (Delphi) | |
W1060 | EXPLICIT_STRING_CAST_LOSS | OFF | Explicit string cast with potential data loss from '%s' to '%s' (Delphi) | |
W1061 | CVT_WCHAR_TO_ACHAR | ON | W1061 Narrowing given WideChar constant ('%s') to AnsiChar lost information (Delphi) | |
W1062 | CVT_NARROWING_STRING_LOST | ON | Narrowing given wide string constant lost information (Delphi) | |
W1063 | CVT_ACHAR_TO_WCHAR | ON | Widening given AnsiChar constant ('%s') to WideChar lost information (Delphi) | |
W1064 | CVT_WIDENING_STRING_LOST | ON | Widening given AnsiString constant lost information (Delphi) | |
W1066 | NON_PORTABLE_TYPECAST | ON | Lost Extended floating point precision. Reduced to Double (Delphi) | |
W1201 | XML_WHITESPACE_NOT_ALLOWED | ON | XML comment on '%s' has badly formed XML-'Whitespace is not allowed at this location.' (Delphi) | |
W1202 | XML_UNKNOWN_ENTITY | ON | XML comment on '%s' has badly formed XML- 'Reference to undefined entity '%s (Delphi) | |
W1203 | XML_INVALID_NAME_START | ON | XML comment on '%s' has badly formed XML-'A name was started with an invalid character.' (Delphi) | |
W1204 | XML_INVALID_NAME | ON | XML comment on '%s' has badly formed XML-'A name contained an invalid character.' (Delphi) | |
W1205 | XML_EXPECTED_CHARACTER | ON | XML comment on '%s' has badly formed XML-'The character '%c' was expected.' (Delphi) | |
W1206 | XML_CREF_NO_RESOLVE | ON | XML comment on '%s' has cref attribute '%s' that could not be resolved (Delphi) | |
W1207 | XML_NO_PARM | ON | XML comment on '%s' has a param tag for '%s', but there is no parameter by that name (Delphi) | |
W1208 | XML_NO_MATCHING_PARM | ON | Parameter '%s' has no matching param tag in the XML comment for '%s' (but other parameters do) (Delphi) |
The $MESSAGE directive allows generation of H1054, W1054, E1054 and F1054 messages. User-defined hint and warning messages can be turned off with {$WARN MESSAGE_DIRECTIVE OFF} but logically enough, user-defined error and fatal messages can not be disabled. For example, add the following line to MyUnit.pas:
{$MESSAGE WARN 'This is a user warning'}Which will gives a compiler warning similar to the following:
[DCC Warning] MyUnit.pas(25): W1054 This is a user warningFinally, I'm not going to discuss the $WARNINGS directive, except to say that I don't think it's ever necessary or sensible to turn it off. If you must turn a warning off for a specific section of code, turn just that warning off as discussed above. Using {$WARNINGS OFF} is just as unhelpful as an empty exceptblock.