delphi指针的定义和取值  
官方Delphi 学习QQ群: 682628230(三千人)
频道

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.


推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.049320936203003 seconds