开发者

Why does the compiler say "Too many actual parameters" when I think I've provided the correct number?

I've d开发者_如何转开发eclared 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?


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."


As specified by Cosmin Prund, the problem is because of the visibility.

TForm has a procedure with name Next 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

if label1.Caption = '' then res := Unit1.next('current', 'next');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜