Delphi有一个$ WARN编译器指令,允许用户有选择地启用或禁用特定警告.Delphi 2009帮助文件描述了语法:
{$WARN identifier ON|OFF}
但它只列出了6个警告的标识符.
我想要一个完整的所有警告标识符列表.特别是,我想知道Delphi 2009中隐式字符串强制转换警告W1057和W1058的标识符.
我设法猜测隐含的Ansi-> Unicode转换(W1057):
{$WARN IMPLICIT_STRING_CAST OFF}
谷歌搜索发现我另一个:
{$WARN IMPLICIT_STRING_CAST_LOSS OFF}
虽然这解决了我的迫切需要,但我仍然想知道完整的警告标识符列表.应该记录这样的东西.
Darian说DCCStrs.pas列出了Delphi编译器使用的标识符.我没有想过搜索源代码,因为Delphi没有将源代码包含在其编译器中.
我从该文件中提取了提示和警告的标识符:
{$WARN ASG_TO_TYPED_CONST OFF}
{$WARN BAD_GLOBAL_SYMBOL OFF}
{$WARN BOUNDS_ERROR OFF}
{$WARN CASE_LABEL_RANGE OFF}
{$WARN COMBINING_SIGNED_UNSIGNED OFF}
{$WARN COMPARING_SIGNED_UNSIGNED OFF}
{$WARN COMPARISON_FALSE OFF}
{$WARN COMPARISON_TRUE OFF}
{$WARN CONSTRUCTING_ABSTRACT OFF}
{$WARN CVT_ACHAR_TO_WCHAR OFF}
{$WARN CVT_NARROWING_STRING_LOST OFF}
{$WARN CVT_WCHAR_TO_ACHAR OFF}
{$WARN CVT_WIDENING_STRING_LOST OFF}
{$WARN DUPLICATE_CTOR_DTOR OFF}
{$WARN DUPLICATES_IGNORED OFF}
{$WARN EXPLICIT_STRING_CAST OFF}
{$WARN EXPLICIT_STRING_CAST_LOSS OFF}
{$WARN FILE_OPEN OFF}
{$WARN FILE_OPEN_UNITSRC OFF}
{$WARN FOR_LOOP_VAR_UNDEF OFF}
{$WARN FOR_LOOP_VAR_VARPAR OFF}
{$WARN FOR_VARIABLE OFF}
{$WARN GARBAGE OFF}
{$WARN HIDDEN_VIRTUAL OFF}
{$WARN HIDING_MEMBER OFF}
{$WARN HPPEMIT_IGNORED OFF}
{$WARN HRESULT_COMPAT OFF}
{$WARN IMAGEBASE_MULTIPLE OFF}
{$WARN IMPLICIT_IMPORT OFF}
{$WARN IMPLICIT_STRING_CAST OFF}
{$WARN IMPLICIT_STRING_CAST_LOSS OFF}
{$WARN IMPLICIT_VARIANTS OFF}
{$WARN INVALID_DIRECTIVE OFF}
{$WARN LOCAL_PINVOKE OFF}
{$WARN LOCALE_TO_UNICODE OFF}
{$WARN MESSAGE_DIRECTIVE OFF}
{$WARN NO_CFG_FILE_FOUND OFF}
{$WARN NO_RETVAL OFF}
{$WARN OPTION_TRUNCATED OFF}
{$WARN PACKAGE_NO_LINK OFF}
{$WARN PACKAGED_THREADVAR OFF}
{$WARN PRIVATE_PROPACCESSOR OFF}
{$WARN RLINK_WARNING OFF}
{$WARN STRING_CONST_TRUNCED OFF}
{$WARN SUSPICIOUS_TYPECAST OFF}
{$WARN SYMBOL_DEPRECATED OFF}
{$WARN SYMBOL_EXPERIMENTAL OFF}
{$WARN SYMBOL_LIBRARY OFF}
{$WARN SYMBOL_PLATFORM OFF}
{$WARN TYPED_CONST_VARPAR OFF}
{$WARN TYPEINFO_IMPLICITLY_ADDED OFF}
{$WARN UNICODE_TO_LOCALE OFF}
{$WARN UNIT_DEPRECATED OFF}
{$WARN UNIT_EXPERIMENTAL OFF}
{$WARN UNIT_INIT_SEQ OFF}
{$WARN UNIT_LIBRARY OFF}
{$WARN UNIT_NAME_MISMATCH OFF}
{$WARN UNIT_PLATFORM OFF}
{$WARN UNSAFE_CAST OFF}
{$WARN UNSAFE_CODE OFF}
{$WARN UNSAFE_TYPE OFF}
{$WARN UNSUPPORTED_CONSTRUCT OFF}
{$WARN USE_BEFORE_DEF OFF}
{$WARN WIDECHAR_REDUCED OFF}
{$WARN XML_CREF_NO_RESOLVE OFF}
{$WARN XML_EXPECTED_CHARACTER OFF}
{$WARN XML_INVALID_NAME OFF}
{$WARN XML_INVALID_NAME_START OFF}
{$WARN XML_NO_MATCHING_PARM OFF}
{$WARN XML_NO_PARM OFF}
{$WARN XML_UNKNOWN_ENTITY OFF}
{$WARN XML_WHITESPACE_NOT_ALLOWED OFF}
{$WARN ZERO_NIL_COMPAT OFF}
我查看了帮助,但没有看到完整的列表...所以在代码中看到编译器警告常量全部列在:CodeGear\RAD Studio\6.0\sources\toolsapi\DCCStrs.pas
搜索"Implicit_String_Cast_Loss",您将看到常量sIMPLICIT_STRING_CAST_LOSS ='DCC_IMPLICIT_STRING_CAST_LOSS';
我假设其余的DCC_xxx字符串与相应的X_true/_false/_error定义是你所追求的.
自Delphi 7以来,在线帮助并不是很好.
Delphi 2009文档中未提及的其他内容:
除了ON和OFF之外,$ WARN指令现在还有第3个选项ERROR.所以你可以:
{$WARN IMPLICIT_STRING_CAST OFF} to disable the warning {$WARN IMPLICIT_STRING_CAST ON} to enable warning {$WARN IMPLICIT_STRING_CAST ERROR} to turn the warning into an error