在 Pascal 中,我可以调用一个函数作为参数的过程吗?

In pascal, can I call a procedure with a function as parameter?

empty(game, left(actualPos));

empty 是有 2 个参数的过程,我想调用一个函数(左)作为第二个参数。这在 Pascal 中可能吗?

谢谢!

如果empty()的第二个参数的类型与left()的return值类型相同(或者left()的值可以是autoconverted/promoted到empty())的第二个参数的类型,第二个参数不是按引用传递(通常声明为var) ,然后您可以调用 empty(),如上所示。

如果两个约束都不为真,则调用将产生一个错误,可能是在编译时。

我在问题中的理解是这样的。我冒昧地猜测细节并省略了一些东西,但代码应该不言而喻(并且是有效的 Delphi 语法):

type
  TGameData=class
    //add more fields here
  end;
  TGamePosition=record
    //add more fields here
  end;
  TSomeGamePosFunc=function(gd:TGameData;gp:TGamePosition): boolean;

  function Left(game:TGameData;APos:TGamePosition): boolean;
  begin
    //if something with the values in the fields of APos then
    Result:=true;
    //else Result:=false;
  end;

  procedure Empty(game:TGameData;something:TSomeGamePosFunc);
  var
    p:TGamePosition;
  begin
    //initialize game
    //for p.x:=0 to width of field
    //for p.y:=0 to height of field?
    //if
    something(game,p);
    //then...
  end;