比如指针p1、p2、p3
p3:=p1-p2,但这样写编译不能通过,请教各位前辈我该当如何写。谢谢!

解决方案 »

  1.   

    不知道你要的是指针值相减还是指向值相减,写了以下演示
    var
      P1,P2,P3: PInteger;//Pointer;
      I1 : Integer = 1111;
      I2 : Integer = 5555;
      I3 : Integer = 3333;procedure TForm1.Button1Click(Sender: TObject);
    begin
      P1 := @I1;
      P2 := @I2;
      P3 := @I3;
      Showmessage(Format('%p,%p,%p',[P1,P2,P3]));//指针值,即地址
      Showmessage(Format('%d,%d,%d',[P1^,P2^,P3^]));//指针指向的数值,即值
      P1^ := P2^ - P3^;
      Showmessage(Format('%d,%d,%d',[P1^,P2^,P3^]));//指针指向的数值,即值,相减后
      Integer(P1) := Integer(P2) - Integer(P3);//指针值相减,即地址相减
      Showmessage(Format('%p,%p,%p',[P1,P2,P3]));//指针值,即地址相减后
    end;
      

  2.   

    是指针相减
    我如下的代码
    type
        funcPointer=procedure;f1,f2,f3:funcPointer;
    Integer(f3):=Integer(f2)-Integer(f1);

    f3:=f2-f1;
    编译都不能通过。
      

  3.   

    指针相减就是这样
    p3^:=p1^-p2^;
      

  4.   

    你声明的不是指针。要这样声明(注意红色的^符)
    f1,f2,f3:^funcPointer;
      

  5.   

    ...原来这里搞错了,不过我用内联汇编实现了。呵呵谢谢各位前辈!asm
            push eax;
            push ecx;
            lea eax,AfterFunc;
            lea ecx,myFunc;
            sub eax,ecx;
            mov cbCodeSize,eax;
            pop ecx;
            pop eax;
    end;