DCC无法弥补功能所需的参数数量

Hal*_*Hal 2 delphi parameters delphi-2010

我在这个原型的单元中声明了一个函数:

function MapFunction(process: THANDLE; func: Pointer; size: Cardinal) : Pointer;
Run Code Online (Sandbox Code Playgroud)

我用它来称呼它:

stub := MapFunction(proc, remoteStub, 80);
Run Code Online (Sandbox Code Playgroud)

当我编译时,我得到这个错误,停止编译:

[DCC错误] test.pas(22):E2035实际参数不足

我摆弄了一段时间,然后决定添加更多参数来看看它在想什么.所以我打电话给它:

stub := MapFunction(proc, remoteStub, 80, 1, 1, 1, 1, 1);
Run Code Online (Sandbox Code Playgroud)

然后DCC通知我:

[DCC错误] test.pas(22):E2035实际参数不足

[DCC错误] test.pas(22):E2034实际参数太多

并注释掉该行允许单元成功编译.

我只有一个问题:什么?

我还应该提到它remoteStub是一个成员变量,这个函数调用是在该类的成员中.并且这种特殊方法是模板方法.

Dav*_*nan 8

您报告该行:

stub := MapFunction(proc, remoteStub, 80, 1, 1, 1, 1, 1);
Run Code Online (Sandbox Code Playgroud)

导致两个错误:

[DCC Error] test.pas(22): E2035 Not enough actual parameters
[DCC Error] test.pas(22): E2034 Too many actual parameters
Run Code Online (Sandbox Code Playgroud)

唯一有意义的解释是:

  • remoteStub 是一个需要参数的函数或过程 - 第一个错误.
  • 所有额外的1个参数都会导致第二个错误.

以下代码的行为与您在问题中以及对RRUZ已删除答案的评论中的报告完全相同:

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;
Run Code Online (Sandbox Code Playgroud)

我想不出还有什么可以解释你报道的内容!