有没有更好的方法向 TMemo 添加一些字符?
我正在使用 TMemo 保存从串行端口接收到的字符以供查看。当他们到达时,我正在做:
Memo1.Text := Memo1.Text + sReceivedChars;
这工作正常,但我认为它效率相当低,必须在连接我的几个字符然后将其写回之前获取现有文本。我真的很想要一个“SendChars()”函数或类似的函数。有没有更好的方法来简单地在现有文本的末尾添加一些字符?
I am using a TMemo to hold received characters from a serial port for viewing. As they arrive I am doing:
Memo1.Text := Memo1.Text + sReceivedChars;
This works fine but I presume it is rather inefficient, having to get the existing text before concatenating my few characters and then writing it back. I would really like a 'SendChars()' function or something similar. Is there a better way of simply adding a few characters on the end of the existing text?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道你是否认为值得,但你可以这样做:
I don't know if you think it's worthwhile, but you can do something like this:
如果您的文本位于多行中(
TStrings
集合的字符串,它是 TMemo 的Lines
属性的实际类型),那么您可以执行以下操作:因此,您将一些字符添加到备忘录的最后一行(字符串集合中的最后一个字符串),而不将整个文本放入单个字符串中。
If your text is in more than one line (strings of a the
TStrings
collection that is the actual type of theLines
property of the TMemo), then you could do this:So you add some chars to the last line (the last string in the string collection) of the memo, without taking the whole text into a single string.