如果F是一个Function类型的指针,var F : Function :Integer;
MyFunction是一个定义好的Function
那么判断两个Function的返回值是否一致,用if F = MyFunction then ...;编译时为什么会出错
改为if @F = @MyFunction then ...;是正确的?为什么取一个procedural变量的内存地址用的是@@?@@MyFunction@不就是取址吗?

解决方案 »

  1.   


    function MyFunc(): Integer;
    begin
      ......
    end;......var
      F : Function: Integer;
    begin
      if F = MyFunc then
      begin
        ......
      end;
    end;
    编译不出错啊?
      

  2.   

    是教材错了,还是我英文太菜了。In some situations it is less clear how a procedural variable should be interpreted. Consider the statement
    if F = MyFunction then ...;
    In this case, the occurrence of F results in a function call; the compiler calls the function pointed to by F, then calls the function
    MyFunction, then compares the results. The rule is that whenever a procedural variable occurs within an expression, it
    represents a call to the referenced procedure or function. In a case where F references a procedure (which doesn't return a
    value), or where F references a function that requires parameters, the previous statement causes a compilation error. To
    compare the procedural value of F with MyFunction, use
    if @F = @MyFunction then ...;
    @F converts F into an untyped pointer variable that contains an address, and @MyFunction returns the address of MyFunction.
    To get the memory address of a procedural variable (rather than the address stored in it), use @@. For example, @@F returns
    the address of F.
      

  3.   

    好像是我的英文太菜了。F如果是个Funciton就对了,如果是个Procedure就出错。
      

  4.   

    procedure没有返回值啊,你到底想比啥?
      

  5.   

    procedrue是没有返回值, 怎么可能"判断两个procedure的返回值是否一致"呢?