字符串

来源:互联网 发布:c51单片机c语言教程 编辑:程序博客网 时间:2024/06/06 04:18

var

  str,s1,s2: string;

  pint: PInteger;

begin

  str := Self.Text; {把窗体标题给它吧现在 str 指向了窗体标题所在的内存位置}

  s1 := str;        {给 s1 赋值}

  s2 := str;        {给 s2 赋值现在窗体标题已经有了 strs1s2 三个引用}

  {strs1s2 的指针肯定不一样但现在指向内存的同一个位置测试:}

  ShowMessage(IntToStr(Integer(str))); {15190384}

  ShowMessage(IntToStr(Integer(s1)));  {15190384}

  ShowMessage(IntToStr(Integer(s2)));  {15190384}

  {向左偏移 个字节就是字符串长度的位置读出它来(肯定是5):}

  pint := PInteger(Integer(str) - 4);

  ShowMessage(IntToStr(pint^));      {5}

  {向左偏移 个字节就是字符串的引用计数读出它来(肯定是3):}

  pint := PInteger(Integer(str) - 8);

  ShowMessage(IntToStr(pint^));      {3}

end;

shortstring 长度+实际字符串 长度是s[0]
string  引用数+长度+实际字符串 

字符串都是字符的数组,是一个指针,的首地址都是@s[1]

因为指针是指向元素的首地址的。故我个人认为,Pchar,pwidechar 是指向s[1]的,不过没验证过这个。

Delphi字符串、PChar

字符串到PChar    p:=PChar(s);

PChar到字符串    s:=p;


原创粉丝点击