Delphi指针的定义和取值


本文整理自网络,侵删。

 

要点:
1.指针的2中定义方法 PInteger 和 ^Integer
2.取地址符号 @ 和 Addr函数
3.取内容符号 ^ ,比如MyPointInt1^则是取MyPointInt1指针所指向的内容了。

 
program MyPoint;  //指针详解
{$APPTYPE CONSOLE}
uses
  SysUtils,windows,Generics.Collections ;

{指针的定义和取值}
procedure MyFunc1();
var
  MyInt : Integer;//整数
  MyPointInt1 : PInteger;//指针定义1
  MyPointInt2 : ^Integer;//指针定义2
begin
  MyInt := 100;
  MyPointInt1 := @MyInt; //取地址方法1
  Writeln('MyInt: ',MyInt,',MyPointInt1:',InttoHex(Integer(MyPointInt1),8),',MyPointInt1^为: ',MyPointInt1^);
  MyPointInt1^ := 200;   //赋值
  MyPointInt2 := Addr(MyInt);//取地址方法2
  Writeln('MyInt: ',MyInt,',MyPointInt2:',InttoHex(Integer(MyPointInt1),8),',MyPointInt1^为: ',MyPointInt1^,',MyPointInt2^为: ',MyPointInt2^);
end;

{main主函数}
begin
 MyFunc1();
 Readln;//回车退出
end.

相关阅读 >>

Delphi getwebbrowserhtml 获取网页源代码

Delphi 如何在richedit控件里加入链接

Delphi firemonkey中listboxaccessory图标切换

Delphi xe android 使用system.zip单元释放资源文件

最简单的Delphi驱动结束进程

Delphi hex 相关单元

Delphi 创建大窗口

Delphi侦测条码枪方式

Delphi getcurrentdir 获取当前文件夹

Delphi 让程序自己更新本程序

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...