如何临时禁用“返回值可能未定义”警告? [英] How can I temporarily disable the "return value might be undefined" warning?

查看:195
本文介绍了如何临时禁用“返回值可能未定义”警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的代码中禁用特定的警告(W1035),因为我认为编译器对此警告错误:

I want to disable a specific warning (W1035) in my code, since I think that the compiler is wrong about this warning:

function TfrmNagScreen.Run: TOption;
begin
  if ShowModal = mrOk then
    Result := TOption(rdgAction.EditValue)
  else
    Abort
end;

没有办法,结果可能未定义,因为 Abort throws EAbort

There is no way the result could be undefined, since Abort throws EAbort.

我尝试过:

  • {$WARN 1035 Off}: Apparently this only works for some specific errors (see Documentation)
  • {$W-1035}: Does nothing at all

我知道我可以在项目选项中关闭全局警告,或使用 {$ WARNINGS OFF} ,但这不是这里的意思。

I know I can switch off the warning globally in the project options, or using {$WARNINGS OFF}, but that is not what is intended here.

编辑: a href =http://qc.embarcadero.com/wc/qcmain.aspx?d=89744>#89744

I have QC'ed this now as #89744.

推荐答案

您不能全局禁用此警告,但您可以使用 {$ WARN NO_RETVAL OFF} 在本地禁用警告。

you can't disable this warning globally, but you can use the {$WARN NO_RETVAL OFF} to disable locally the warning.

{$WARN NO_RETVAL OFF}
function TfrmNagScreen.Run: TOption;
begin
  if ShowModal = mrOk then
    Result := TOption(rdgAction.EditValue)
  else
    Abort
end;
{$WARN NO_RETVAL ON}

这篇关于如何临时禁用“返回值可能未定义”警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆