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):
{$WARN SYMBOL_DEPRECATED ON}
{$WARN SYMBOL_DEPRECATED OFF}
To restore the warning to its previous setting:
{$WARN SYMBOL_DEPRECATED DEFAULT}
And finally, you can convert a warning into an error:
{$WARN SYMBOL_DEPRECATED ERROR}
To change the setting in your project, go to Project|Options, Delphi Compiler, Hints and Warnings, and expand the Output warnings setting:
Delphi's project options dialog - hints and warnings




To change the setting in the command line compiler, use the -W flag, for example:
dcc32 -W+SYMBOL_DEPRECATED myproject.dpr
dcc32 -W-SYMBOL_DEPRECATED myproject.dpr
Or to turn the warning into an error:
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
These 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 IDDefaultDescriptionNotes
W1000SYMBOL_DEPRECATEDOFFSymbol '%s' is deprecated (Delphi) 
W1001SYMBOL_LIBRARYOFFSymbol '%s' is specific to a library (Delphi) 
W1002SYMBOL_PLATFORMOFFSymbol '%s' is specific to a platform (Delphi) 
W1003SYMBOL_EXPERIMENTALONSymbol '%s' is experimental (Delphi) 
W1004UNIT_LIBRARYOFFUnit '%s' is specific to a library (Delphi) 
W1005UNIT_PLATFORMOFFUnit '%s' is specific to a platform (Delphi) 
W1006UNIT_DEPRECATEDOFFUnit '%s' is deprecated (Delphi) 
W1007UNIT_EXPERIMENTALONUnit '%s' is experimental (Delphi) 
W1008HRESULT_COMPATONInteger and HRESULT interchanged 
W1009HIDING_MEMBERONRedeclaration of '%s' hides a member in the base class (Delphi) 
W1010HIDDEN_VIRTUALONMethod '%s' hides virtual method of base type '%s' (Delphi) 
W1011GARBAGEONText after final 'END.' - ignored by compiler (Delphi) 
W1012BOUNDS_ERRORONConstant expression violates subrange bounds 
W1013ZERO_NIL_COMPATONConstant 0 converted to NIL (Delphi) 
W1014STRING_CONST_TRUNCEDONString constant truncated to fit STRING%ld (Delphi) 
W1015FOR_LOOP_VAR_VARPARONFOR-Loop variable '%s' cannot be passed as var parameter (Delphi) 
W1016TYPED_CONST_VARPARONTyped constant '%s' passed as var parameter (Delphi) 
W1017ASG_TO_TYPED_CONSTONAssignment to typed constant '%s' (Delphi) 
W1018CASE_LABEL_RANGEONCase label outside of range of case expression (Delphi) 
x1019FOR_VARIABLEONFor loop control variable must be simple local variable (Delphi) 
x1020CONSTRUCTING_ABSTRACTONConstructing instance of '%s' containing abstract method '%s.%s' (Delphi) 
W1021COMPARISON_FALSEONComparison always evaluates to False (Delphi) 
W1022COMPARISON_TRUEONComparison always evaluates to True (Delphi) 
W1023COMPARING_SIGNED_UNSIGNEDONComparing signed and unsigned types - widened both operands (Delphi) 
W1024COMBINING_SIGNED_UNSIGNEDONCombining signed and unsigned types - widened both operands (Delphi) 
x1025UNSUPPORTED_CONSTRUCTONUnsupported language feature: '%s' (Delphi) 
x1026FILE_OPENONFile not found '%s' (Delphi)Despite being listed as a warning, turning this off appears to have no effect.
F1027FILE_OPEN_UNITSRCONUnit not found '%s' or binary equivalents (%s) (Delphi) 
x1028BAD_GLOBAL_SYMBOLONBad global symbol definition '%s' in object file '%s' (Delphi) 
W1029DUPLICATE_CTOR_DTORONDuplicate %s '%s' with identical parameters will be inacessible from C++ (Delphi) 
x1030INVALID_DIRECTIVEONInvalid compiler directive - '%s' (Delphi) 
W1031PACKAGE_NO_LINKONPackage '%s' will not be written to disk because -J option is enabled (Delphi) 
W1032PACKAGED_THREADVARONExported package threadvar '%s.%s' cannot be used outside of this package (Delphi) 
W1033IMPLICIT_IMPORTONUnit '%s' implicitly imported into package '%s' (Delphi) 
W1034HPPEMIT_IGNOREDON$HPPEMIT '%s' ignored (Delphi) 
W1035NO_RETVALONReturn value of function '%s' might be undefined (Delphi) 
W1036USE_BEFORE_DEFONVariable '%s' might not have been initialized (Delphi) 
W1037FOR_LOOP_VAR_UNDEFONFOR-Loop variable '%s' may be undefined after loop (Delphi) 
E1038UNIT_NAME_MISMATCHONUnit identifier '%s' does not match file name (Delphi) 
W1039NO_CFG_FILE_FOUNDONNo configuration files found (Delphi) 
W1040IMPLICIT_VARIANTSONImplicit use of Variants unit (Delphi) 
W1041UNICODE_TO_LOCALEONError converting Unicode char to locale charset. String truncated. Is your LANG environment variable set correctly (Delphi) 
W1042LOCALE_TO_UNICODEONError converting locale string '%s' to Unicode. String truncated. Is your LANG environment variable set correctly (Delphi) 
W1043IMAGEBASE_MULTIPLEONImagebase $%X is not a multiple of 64k. Rounding down to $%X (Delphi) 
W1044SUSPICIOUS_TYPECASTONSuspicious typecast of %s to %s (Delphi) 
W1045PRIVATE_PROPACCESSORONProperty declaration references ancestor private '%s.%s' (Delphi) 
W1046UNSAFE_TYPEOFFUnsafe type '%s%s%s' (Delphi) 
W1047UNSAFE_CODEOFFUnsafe code '%s' (Delphi) 
W1048UNSAFE_CASTOFFUnsafe typecast of '%s' to '%s' (Delphi) 
W1049OPTION_TRUNCATEDONvalue '%s' for option %s was truncated (Delphi) 
W1050WIDECHAR_REDUCEDONWideChar reduced to byte char in set expressions (Delphi) 
W1051DUPLICATES_IGNOREDONDuplicate symbol names in namespace. Using '%s.%s' found in %s. Ignoring duplicate in %s (Delphi) 
W1052UNIT_INIT_SEQONCan't find System.Runtime.CompilerServices.RunClassConstructor. Unit initialization order will not follow uses clause orderDoes not seem to be documented in XE2
W1053LOCAL_PINVOKEONLocal PInvoke code has not been made because external routine '%s' in package '%s' is defined using package local types in its custom attributesDoes not seem to be documented in XE2
x1054MESSAGE_DIRECTIVEON%s (Delphi)User-defined warning messages (see below). Turns off message hints as well but not message errors.
W1055TYPEINFO_IMPLICITLY_ADDEDONPublished caused RTTI ($M+) to be added to type '%s' (Delphi) 
x1056RLINK_WARNINGONDuplicate resource Type %s, ID %s; File %s resource kept; file %s resource discarded (Delphi) 
W1057IMPLICIT_STRING_CASTONImplicit string cast from '%s' to '%s' (Delphi) 
W1058IMPLICIT_STRING_CAST_LOSSONImplicit string cast with potential data loss from '%s' to '%s' (Delphi) 
W1059EXPLICIT_STRING_CASTOFFExplicit string cast from '%s' to '%s' (Delphi) 
W1060EXPLICIT_STRING_CAST_LOSSOFFExplicit string cast with potential data loss from '%s' to '%s' (Delphi) 
W1061CVT_WCHAR_TO_ACHARONW1061 Narrowing given WideChar constant ('%s') to AnsiChar lost information (Delphi) 
W1062CVT_NARROWING_STRING_LOSTONNarrowing given wide string constant lost information (Delphi) 
W1063CVT_ACHAR_TO_WCHARONWidening given AnsiChar constant ('%s') to WideChar lost information (Delphi) 
W1064CVT_WIDENING_STRING_LOSTONWidening given AnsiString constant lost information (Delphi) 
W1066NON_PORTABLE_TYPECASTONLost Extended floating point precision. Reduced to Double (Delphi) 
W1201XML_WHITESPACE_NOT_ALLOWEDONXML comment on '%s' has badly formed XML-'Whitespace is not allowed at this location.' (Delphi) 
W1202XML_UNKNOWN_ENTITYONXML comment on '%s' has badly formed XML- 'Reference to undefined entity '%s (Delphi) 
W1203XML_INVALID_NAME_STARTONXML comment on '%s' has badly formed XML-'A name was started with an invalid character.' (Delphi) 
W1204XML_INVALID_NAMEONXML comment on '%s' has badly formed XML-'A name contained an invalid character.' (Delphi) 
W1205XML_EXPECTED_CHARACTERONXML comment on '%s' has badly formed XML-'The character '%c' was expected.' (Delphi) 
W1206XML_CREF_NO_RESOLVEONXML comment on '%s' has cref attribute '%s' that could not be resolved (Delphi) 
W1207XML_NO_PARMONXML comment on '%s' has a param tag for '%s', but there is no parameter by that name (Delphi) 
W1208XML_NO_MATCHING_PARMONParameter '%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 warning
Finally, 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.
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值