为什么编译器会说“实际参数过多”当我认为我提供了正确的号码时?
我已经声明了以下函数:
function next(current, next: string): Integer;
begin
form1.Label1.Caption := next;
form1.Label2.Caption := current;
form1.label3.Caption := clipboard.AsText+inttostr(c);
Result:=1;
end;
我尝试使用以下代码执行它:
if label1.Caption = '' then res := next('current', 'next');
我收到以下错误:
[错误] Unit1.pas(47): E2034 太多 实际参数
我认为所有参数都很好,那么为什么我会收到该错误?
I've declared the following function:
function next(current, next: string): Integer;
begin
form1.Label1.Caption := next;
form1.Label2.Caption := current;
form1.label3.Caption := clipboard.AsText+inttostr(c);
Result:=1;
end;
I try to execute it with this code:
if label1.Caption = '' then res := next('current', 'next');
I am getting the following error:
[Error] Unit1.pas(47): E2034 Too many
actual parameters
I think all parameters are good, so why am I getting that error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我刚刚在 Delphi 7 和 Delphi 2010 上尝试了您的代码。如果它适用于这两个版本,那么它也应该适用于 Delphi 2005。
结论:由于代码范围/可见性,Delphi 希望使用“下一个”例程的不同版本。尝试按 ctrl+单击“res := next();”中的“next”看看德尔福带您去往何处。或者发布更多代码,以便我们可以告诉您为什么 Delphi 没有选择您的“下一个”例程版本。理想情况下,您应该发布整个单元,从“单元名称”开始到最终“结束”。
I just tried your code on both Delphi 7 and Delphi 2010. If it works on those two, it should also work on Delphi 2005.
Conclusion: Delphi wants to use a different version of the "next" routine, because of code scope/visibility. Try ctrl+click-ing on "next" in "res := next();" and see where Delphi takes you. Alternatively post more code so we can tell you why Delphi is not choosing your version of the "next" routine. Ideally you should post a whole unit, starting from "unit name" to the final "end."
正如 Cosmin Prund 所指出的,问题在于可见性。
TForm
有一个名为Next
的过程,它不接受任何参数。您的函数使用相同的名称,并且当您在 TForm1 类实现中调用该函数时,编译器会将调用视为
TForm1.Next
,因此会出现错误。要解决此问题,请将单元名称放在函数名称之前,即
Unit1.Next()
。所以这应该是你的代码
As specified by Cosmin Prund, the problem is because of the visibility.
TForm
has a procedure with nameNext
which wont accept any parameters.Your function uses the same name and as you are calling the function in TForm1 class implementation, compiler is treating the call as
TForm1.Next
and hence it was giving error.To solve the problem, precede the unit name before the function name i.e.,
Unit1.Next()
.So this should be your code