Why does the compiler say “Too many actual parameters” when I think I provided the correct number?

I 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 am trying to execute it with this code:

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

I get the following error:

[Error] Unit1.pas (47): E2034 Too many actual parameters

I think all parameters are good, so why am I getting this error?

+4
source share
2 answers

I just tried my code on both Delphi 7 and Delphi 2010. If it works on these two, it should also work on Delphi 2005.

Conclusion: Delphi wants to use a different version of the “next” procedure because of the visibility / visibility of the code. Try ctrl + click on on "next" in "res: = next ();" and see where Delphi takes you. Alternatively, send more code so we can tell you why Delphi does not select your version of the “next” procedure. Ideally, you should place the whole unit, from the "unit name" to the final "end".

+7
source

As pointed out by Cosmin Prund, the problem is visibility.

TForm has a procedure called Next that does not accept any parameters.

Your function uses the same name and, as you call the function in the implementation of the TForm1 class, the compiler processes the call as TForm1.Next and therefore it gives an error.

To solve the problem, precede the device name with the function name ie, Unit1.Next() .

So this should be your code

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

All Articles