delphi如果将两指针相减 比如指针p1、p2、p3p3:=p1-p2,但这样写编译不能通过,请教各位前辈我该当如何写。谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不知道你要的是指针值相减还是指向值相减,写了以下演示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; 是指针相减我如下的代码type funcPointer=procedure;f1,f2,f3:funcPointer;Integer(f3):=Integer(f2)-Integer(f1);或f3:=f2-f1;编译都不能通过。 指针相减就是这样p3^:=p1^-p2^; 你声明的不是指针。要这样声明(注意红色的^符)f1,f2,f3:^funcPointer; ...原来这里搞错了,不过我用内联汇编实现了。呵呵谢谢各位前辈!asm push eax; push ecx; lea eax,AfterFunc; lea ecx,myFunc; sub eax,ecx; mov cbCodeSize,eax; pop ecx; pop eax;end; Delphi 中用 Xml 配置文档生成 Treeview 现在招聘程序员就像…… 安装后运行,提示没找到VCLJPG70.BPL? 今天是大年初一 我给大伙拜年哪 放分 100 select distinct field_1 from table_1 ,开发环境下正常,转到例外一台机器上运行查询出table_1中的所有记录,奇怪!! 重新画dbgrid 为什么网页上的一些广告和某些内容显示不出来? 帮忙找错误! 怎样对数组赋值??? 高手们!如何阻止数据感知组件换行保存 想做个数据库连接异常的人性化处理 猪妞,生日快乐……6
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;
我如下的代码
type
funcPointer=procedure;f1,f2,f3:funcPointer;
Integer(f3):=Integer(f2)-Integer(f1);
或
f3:=f2-f1;
编译都不能通过。
p3^:=p1^-p2^;
f1,f2,f3:^funcPointer;
push eax;
push ecx;
lea eax,AfterFunc;
lea ecx,myFunc;
sub eax,ecx;
mov cbCodeSize,eax;
pop ecx;
pop eax;
end;