Delphi指针长度


本文整理自网络,侵删。

 

要点:
1.指针指向的内容的大小因数据类型的不同而不同,指针本事的大小,都是4字节
2.sizeof函数是取形参所占的内存大小
3.IntToHex是把整数型的值,转换为16进制的值,第二个参数是16进制的长度为多少位


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

{指针长度}
procedure MyFunc3();
var
  MyInt : Integer;//整数
  MyPoint : PInteger; //定义指针
  MyByte : Byte;
  MyPintByte : PByte;
begin
  MyInt := 2;
  MyByte := 3;
{byte型和integer型的指针}
  MyPoint := @MyInt;
  MyPintByte := @MyByte;
{输出2者地址}
  Writeln('MyPoint    :' + IntToHex(Integer((MyPoint)),8));
  Writeln('MyPintByte :' + IntToHex(Integer((MyPintByte)),8));
  Inc(MyPoint);
  Inc(MyPintByte);
{调用Inc之后byte和integer地址一个多1,一个多4}
  Writeln('MyPoint    :' + IntToHex(Integer(MyPoint),8));
  Writeln('MyPintByte :' + IntToHex(Integer(MyPintByte),8));
{byte和integer指针取自身长度都是4}
  Writeln('SizeOf(MyInt):'+IntToStr(SizeOf(MyInt))+' SizeOf(MyPoint):'+IntToStr(SizeOf(MyPoint)));
  Writeln('SizeOf(MyByte):'+IntToStr(SizeOf(MyByte))+' SizeOf(MyPintByte):'+IntToStr(SizeOf(MyPintByte)));
end;

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

相关阅读 >>

Delphi controls 属性与继承 tshape 类的小练习

Delphi rest服务器返回图像并显示在浏览器中

Delphi 圆角panel

Delphi idsmtp控件发送邮件

Delphi http远程屏幕源码

Delphi获取控件界面图像“新招”

Delphi tms web core twebhttprequest使用

Delphi-xe5-开发 android uri简介

Delphi获取图片的真实类型

Delphi 注入指定进程

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



打赏

取消

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

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

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

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

评论

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