【问题标题】:DCC Can't make up it's mind about the number of parameters a function needsDCC 无法确定函数需要的参数数量
【发布时间】:2013-10-04 07:22:43
【问题描述】:

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

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

我用这个来称呼它:

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

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

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

我摆弄了一会儿,然后决定添加更多参数来看看它在想什么。所以我用这个来称呼它:

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

然后 DCC 通知我:

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

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

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

我只有一个问题:什么?

我还应该提到remoteStub 是一个成员变量,这个函数调用在该类的一个成员中。而且这个特定的方法是一个模板方法。

【问题讨论】:

  • 这种情况下的proc是什么?如果 proc 是需要参数的方法,您可能会收到此类消息。
  • @johnny:这也是我的猜测——proc 听起来很可疑。 :-)
  • 告诉我们procremoteStub是什么。
  • 如果 remoteStub 是一个函数,并且您需要将其作为参数(而不是结果)提供,您应该获取其入口点上的指针 - @remoteStub

标签: delphi parameters delphi-2010


【解决方案1】:

您报告该行:

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 参数都会导致第二个错误。

以下代码的行为与您在问题和 cmets 中报告给 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;

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

【讨论】:

    【解决方案2】:

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

    下面的代码给你一个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.
    

    【讨论】:

    • 我也想过,但无法解释看到 E2035 和 E2034 在同一源代码行报告。
    猜你喜欢
    • 1970-01-01
    • 2013-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-10
    • 1970-01-01
    • 2015-03-23
    • 2019-09-16
    相关资源
    最近更新 更多