为什么AnsiString型变量被强制类型PChar后,要手工调用RealizeLength来恢复原来以null结尾的长度?(100分)

  • 主题发起人 主题发起人 鼹鼠
  • 开始时间 开始时间

鼹鼠

Unregistered / Unconfirmed
GUEST, unregistred user!
PChar不也是以null结尾吗?难道AnsiString类型变量被强制类型PChar后,其长度
改变了?
 
Long string to PChar conversions are not automatic. Some of the differences between
strings and PChars can make conversions problematic:

Long strings are reference-counted, while PChars are not.
Assigning to a string copies the data, while a PChar is a pointer to memory.
Long strings are null-terminated and also contain the length of the string,
while PChars are simply null-terminated.

Situations in which these differences can cause subtle errors are discussed
in this section.


以上是Borland的官方解答。
 
接受答案了.
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
913
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
735
import
I
后退
顶部