• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

delphiBerlin10.1string、AnsiString及Tbytes等之间的转换

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

1.类型说明

 

Byte:Represents an 8-bit unsigned integer type.

[PByte:Is a pointer to a Byte.]

 

Char:Represents a word-sized (16-bits) character type

AnsiChar:Represents a byte-sized (8-bits) character type

WideChar:Represents a word-sized (16-bits) character type.

[PChar:Defines a null-terminated string]

[PAnsiChar:Defines a null-terminated ANSI string.]

 

String:Represents an alias for the generic UnicodeString type.

AnsiString:Represents a dynamically allocated string whose maximum length is limited only by available memory.

WideString:A null-terminated string of wide characters, with no reference counting.

[PString:Is a pointer to a String.]

[PAnsiString:Is a pointer to an AnsiString.]

 

TBytes:declares an array of Bytes.

 

2.指针

 

 1         var

 2           X, Y: Integer;  // X and Y are Integer variables

 3           P: ^Integer;     // P points to an Integer

 4         begin

 5           X := 17;      // assign a value to X

 6           P := @X;      // assign the address of X to P

 7           Y := P^;      // dereference P; assign the result to Y

 8         end;

 

type

  PInteger = ^Integer;

var

  R: Single;

  I: Integer;

  P: Pointer;

  PI: PInteger;

begin

  ...

  P := @R;

  PI := PInteger(P);

  I := PI^;

end;

 

3.一些点

 

SizeOf:Returns the number of bytes occupied by a variable or type.

Length:Returns the number of characters in a string or of elements in an array. 

Move:Copies bytes from a source to a destination. e.g.: Move(PChar(@arrBuf[0])^, LPChar^, aSectorNum * 512);

ByteLength:Returns the length of a given string in bytes.

GetBytes:Encodes a set of characters into a sequence of bytes

FillChar:Fills contiguous bytes with a specified value.

 

 

4.转换

 

TBytes -> PChar :     LPChar :=  PChar(LTBytes);

PChar -> TBytes:LTBytes := BytesOf(LPChar);

TBytes -> Array of AnsiChar:move(LTBytes[i],LArrayOfAnsiChar[k]);

Array of AnsiChar -> string:LString := StringOf(BytesOf(LArrayOfAnsiChar));


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#实现局部峰值查找,功能对应Matlab中的findpeaks.m发布时间:2022-07-18
下一篇:
Matlab GUI设计(2)发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap