Hal
Hal

Reputation: 175

DCC Can't make up it's mind about the number of parameters a function needs

I have a function declared in a unit with this prototype:

function MapFunction(process: THANDLE; func: Pointer; size: Cardinal) : Pointer;

and I am calling it with this:

stub := MapFunction(proc, remoteStub, 80);

When I compile I get this error which halts compilation:

[DCC Error] test.pas(22): E2035 Not enough actual parameters

I fiddled with it for a while and just decided to add more parameters to see what it was thinking. So I called it with this:

stub := MapFunction(proc, remoteStub, 80, 1, 1, 1, 1, 1);

And then DCC informs me that:

[DCC Error] test.pas(22): E2035 Not enough actual parameters

[DCC Error] test.pas(22): E2034 Too many actual parameters

And commenting out that line allows the unit to compile successfully.

I just have one question: What?

I should also mention that remoteStub is a member variable and this function call is inside a member of that class. And that this particular method is a template method.

Upvotes: 2

Views: 359

Answers (2)

Wouter van Nifterick
Wouter van Nifterick

Reputation: 24116

Make sure that you don't have other functions with the same name and a different signature.

The code below gives you a E2035 Not enough actual parameters

program Project41;
{$APPTYPE CONSOLE}
uses SysUtils;

// GetFileVersion also exists in SysUtils
function GetFileVersion(const AFileName: string;extraparam:Integer): Cardinal;
begin
  beep;
end;

begin
  GetFileVersion(ParamStr(0));
end.

Upvotes: 0

David Heffernan
David Heffernan

Reputation: 613521

You report that the line:

stub := MapFunction(proc, remoteStub, 80, 1, 1, 1, 1, 1);

results in two errors:

[DCC Error] test.pas(22): E2035 Not enough actual parameters
[DCC Error] test.pas(22): E2034 Too many actual parameters

The only explanation that makes sense is that:

  • remoteStub is a function or procedure which expects parameters – the first error.
  • all the extra 1 parameters result in the second error.

The following code behaves exactly as you report in your question and in comments to RRUZ's deleted answer:

function MapFunction(process: THANDLE; func: Pointer; size: Cardinal) : Pointer;
begin
  Result := nil;
end;

var
  remoteStub: procedure(x: Integer);

procedure remoteStub2(x: Integer);
begin
end;

procedure Test;
begin
  remoteStub := remoteStub2;

  //E2035 Not enough actual parameters
  MapFunction(0, remoteStub, 0);
  MapFunction(0, remoteStub2, 0);

  //Compiles and passes the entry point of the procedure
  MapFunction(0, @remoteStub, 0);
  MapFunction(0, @remoteStub2, 0);
end;

I can't think what else could explain what you report!

Upvotes: 8

Related Questions