4

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?

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
djcis
  • 93
  • 1
  • 4
  • 7
    It's just a guess but I believe it's the fact that both the parameter name and function name is the same. Try to add for exmple 'A' before the parameter name. – johnny Dec 07 '10 at 08:46

2 Answers2

7

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
  • 25,498
  • 2
  • 60
  • 104
7

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');
Bharat
  • 6,828
  • 5
  • 35
  • 56