为什么 Delphi 编译器允许在方法调用的最后一个参数后面使用逗号?

发布于 2024-12-26 05:11:56 字数 492 浏览 3 评论 0原文

假设我有一个像这样的函数,

procedure TMyObject.DoSomething(text: string);
begin
    // do something important with the text
end;

当我调用这样的方法时,

DoSomething('some text', );

代码编辑器在最后一个参数后面的逗号处显示红色波浪线,正如我所期望的那样。然而,编译器接受此代码,并且一切正常,就好像逗号不存在一样。

为什么这看起来是合法的语法?是否有一些历史原因今天仍然支持(我在 Delphi 2006 和 其他好像2007年也经历过)?

Say I had a function such as this one

procedure TMyObject.DoSomething(text: string);
begin
    // do something important with the text
end;

When I call the method like so

DoSomething('some text', );

the code editor displays a red squiggly at the comma after the last parameter, just as I would have expected. The compiler, however, accepts this code and everything works as if the comma wasn't there.

Why does this appear to be legal syntax? Is there some historical reason this is still supported today (I have tried this in Delphi 2006 and others seemed to have experienced it in 2007 as well)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

近箐 2025-01-02 05:11:56

该代码会在 Delphi 6、2010 和 XE2 中导致编译错误(E2034 实际参数过多)。我猜这是您版本中的编译器错误,因为它不是合法的语法。

That codes results in a compile error (E2034 Too many actual parameters) in Delphi 6, 2010 and XE2. I guess it's a compiler bug in your version since it is not legal syntax.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文