Warning messages (Delphi)

From RAD Studio
Jump to: navigation, search

Go Up to Delphi Compiler Directives (List) Index


Type Switch
Syntax {$WARN identifier ON | OFF | ERROR | DEFAULT}
Default All warnings are enabled
Scope Local

The $WARN directive gives you fine-grained control over individual warning messages.

The only warnings that can be turned on/off using $WARN are the ones listed below.

The warnings set by the inline $WARN directive are carried for the compilation unit in which the directive appears, after which it reverts to the previous state. The warnings set by a $WARN directive take effect from that point on in the file.

The $WARNINGS directive also controls the generation of compiler warnings.

ON, OFF, ERROR and DEFAULT

You can use the $WARN directive as follows:

Syntax Effect
{$WARN identifier ON} Allows the compiler to display the warning specified by the identifier.
{$WARN identifier OFF} The specified warning is not displayed.
{$WARN identifier ERROR} The specified warning is treated as error.
{$WARN identifier DEFAULT} Uses the default settings from the Project Options dialog box.

Identifiers

The identifier in the $WARN directive can have any of the following values:

Identifier Warning
SYMBOL_DEPRECATED W1000
SYMBOL_LIBRARY W1001
SYMBOL_PLATFORM W1002
SYMBOL_EXPERIMENTAL W1003
UNIT_LIBRARY W1004
UNIT_PLATFORM W1005
UNIT_DEPRECATED W1006
UNIT_EXPERIMENTAL W1007
HRESULT_COMPAT W1008
HIDING_MEMBER W1009
HIDDEN_VIRTUAL W1010
GARBAGE W1011
BOUNDS_ERROR W1012
ZERO_NIL_COMPAT W1013
STRING_CONST_TRUNCED W1014
FOR_LOOP_VAR_VARPAR W1015
TYPED_CONST_VARPAR W1016
ASG_TO_TYPED_CONST W1017
CASE_LABEL_RANGE W1018
FOR_VARIABLE W1019
CONSTRUCTING_ABSTRACT W1020
COMPARISON_FALSE W1021
COMPARISON_TRUE W1022
COMPARING_SIGNED_UNSIGNED W1023
COMBINING_SIGNED_UNSIGNED W1024
UNSUPPORTED_CONSTRUCT W1025
FILE_OPEN W1026
FILE_OPEN_UNITSRC W1027
BAD_GLOBAL_SYMBOL W1028
DUPLICATE_CTOR_DTOR W1029
INVALID_DIRECTIVE W1030
PACKAGE_NO_LINK W1031
PACKAGED_THREADVAR W1032
IMPLICIT_IMPORT W1033
HPPEMIT_IGNORED W1034
NO_RETVAL W1035
USE_BEFORE_DEF W1036
FOR_LOOP_VAR_UNDEF W1037
UNIT_NAME_MISMATCH W1038
NO_CFG_FILE_FOUND W1039
IMPLICIT_VARIANTS W1040
UNICODE_TO_LOCALE W1041
LOCALE_TO_UNICODE W1042
IMAGEBASE_MULTIPLE W1043
SUSPICIOUS_TYPECAST W1044
PRIVATE_PROPACCESSOR W1045
UNSAFE_TYPE W1046
UNSAFE_CODE W1047
UNSAFE_CAST W1048
OPTION_TRUNCATED W1049
WIDECHAR_REDUCED W1050
DUPLICATES_IGNORED W1051
MESSAGE_DIRECTIVE W1054
TYPEINFO_IMPLICITLY_ADDED W1055
RLINK_WARNING W1056
IMPLICIT_STRING_CAST W1057
IMPLICIT_STRING_CAST_LOSS W1058
EXPLICIT_STRING_CAST W1059
EXPLICIT_STRING_CAST_LOSS W1060
CVT_WCHAR_TO_ACHAR W1061
CVT_NARROWING_STRING_LOST W1062
CVT_ACHAR_TO_WCHAR W1063
CVT_WIDENING_STRING_LOST W1064
LOST_EXTENDED_PRECISION W1066
LNKDFM_NOTFOUND W1067
IMMUTABLE_STRINGS W1068
MOBILE_DELPHI W1069
UNSAFE_VOID_POINTER W1070
IMPLICIT_INTEGER_CAST_LOSS W1071
IMPLICIT_CONVERSION_LOSS W1072
COMBINING_SIGNED_UNSIGNED64 W1073
UNKNOWN_CUSTOM_ATTRIBUTE W1074
XML_WHITESPACE_NOT_ALLOWED W1201
XML_UNKNOWN_ENTITY W1202
XML_INVALID_NAME_START W1203
XML_INVALID_NAME W1204
XML_EXPECTED_CHARACTER W1205
XML_CREF_NO_RESOLVE W1206
XML_NO_PARM W1207
XML_NO_MATCHING_PARM W1208

Examples

The following $WARN directive results in warnings about all references to experimental symbols in the current module:

{$WARNINGS ON}
{$WARN SYMBOL_EXPERIMENTAL ON}

procedure Foo; experimental;
begin
end;

begin
    Foo // Warning: W1003 Symbol 'Foo' is experimental
end.

If that $WARN directive were changed to:

{$WARN SYMBOL_EXPERIMENTAL ERROR}

then the compiler message would change to:

Error: E1003 Symbol 'Foo' is experimental

and this module would not be compiled.

Another example:

{$WARN WIDECHAR_REDUCED OFF}
  if c in ['a', 'b'] then
    // ...
{$WARN WIDECHAR_REDUCED DEFAULT}

See Also