为了账号安全,请及时绑定邮箱和手机立即绑定

为什么write方法要用TmpStr[1],不能直接用tmpsrt?

为什么write方法要用TmpStr[1],不能直接用tmpsrt?

鸿蒙传说 2022-05-28 17:13:51
varmystream:TmemoryStream;TmpStr:string;MyStream:=TMemoryStream.Create;TmpStr:=Edit2.Text;tryMyStream.Write(TmpStr[1],Length(edit2.text));//z这里不懂 怎么不能直接用tmpsrt字符变量NMudp1.sendstream(Mystream);finally具体问题是上面的 mysrteam 的write方法为什么要用TmpStr[1],不能直接用tmpsrt还有就是 MyStream.Write(TmpStr[1],Length(edit2.text))这句执行的目的是什么 返回什么 把什么给了什么
查看完整描述

1 回答

?
慕斯王

TA贡献1864条经验 获得超2个赞

用TmpStr[1]是因为DELPHI字符串类型的原因,因为长字符串中,TmpStr是代表的字符串存储的地址,而TmpStr[1]就是字符串第一个字符的位置,我是这么理解的。所以要用TmpStr[1]。
delphi的帮助中对TmemoryStream的write方法是这样描述的:
Writes Count bytes from Buffer to the current position in the memory buffer and updates the current position by Count bytes.

Delphi syntax:

function Write(const Buffer; Count: Longint): Longint; override;

C++ syntax:

virtual int __fastcall Write(const void *Buffer, int Count);

Description

Use Write to insert Count bytes into the memory buffer of the memory stream, starting at the current position. Write will increase the size of the memory buffer, if necessary, to accommodate the data being written in. If the current position is not the end of the memory buffer, Write will overwrite the data following the current position.

Write updates the Size property to Position + Count, and sets the Position property to the new value of Size. Thus, any data that was stored in the memory stream in the Count bytes after the current position is lost when calling Write.

Write always writes the Count bytes in the Buffer, unless there is a memory failure. Thus, for TMemoryStream, Write is equivalent to the WriteBuffer method.

All other data-writing methods of a memory stream (WriteBuffer, WriteComponent) call Write to do the actual writing.
---------------------
MyStream.Write(TmpStr[1],Length(edit2.text)) 是把TmpStr串中的内容写到MyStream内存流里面,Length(edit2.text)是写入的字符数


查看完整回答
反对 回复 2022-05-30
  • 1 回答
  • 0 关注
  • 232 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号