DCC 无法决定函数需要的参数数量

发布于 2024-10-23 19:20:47 字数 698 浏览 2 评论 0原文

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

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

并且我用以下方式调用它:

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

当我编译时,我收到此错误,该错误停止编译:

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

我摆弄了它一段时间,只是决定添加更多参数来看看它在想什么。所以我这样称呼它:

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

然后 DCC 通知我:

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

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

注释掉该行可以使单元编译成功。

我只有一个问题:什么?

我还应该提到的是,remoteStub 是一个成员变量,并且此函数调用位于该类的成员内部。并且这个特定方法是模板方法。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如果没结果 2024-10-30 19:20:47

您报告该行:

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

导致两个错误:

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

唯一有意义的解释是:

  • 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;

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

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!

淡莣 2024-10-30 19:20:47

确保您没有其他具有相同名称和不同签名的函数。

下面的代码给你一个E2035没有足够的实际参数

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.

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文