简体   繁体   English

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

[英]Why does the Delphi compiler allow a comma after the final parameter in a method call?

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)? 是否有一些历史原因今天仍然支持(我在Delphi 2006中试过这个, 其他人似乎也在2007年经历过这个)?

That codes results in a compile error (E2034 Too many actual parameters) in Delphi 6, 2010 and XE2. 该代码导致Delphi 6,2010和XE2中的编译错误(E2034实际参数太多)。 I guess it's a compiler bug in your version since it is not legal syntax. 我想这是你的版本中的编译器错误,因为它不是合法的语法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM