在delphi中读取Tmemo的最后一行 [英] Reading the last line in a Tmemo in delphi

查看:620
本文介绍了在delphi中读取Tmemo的最后一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试了很长时间之后...决定寻求帮助.

After trying for a very long time .... decided to ask for help.

我正在尝试阅读发送到Delphi中的Tmemo的最后一行.我正在将代码行一一发送给开发人员.登上开发人员.电路板每次都需要发送不同的代码行.我的最终目标是回读开发人员的最后一行.板发回.

I'm trying to read the last line sent to a Tmemo in Delphi. I'm sending lines of code one by one to a dev. board the dev. board needs different lines of code sent to it every time. My end goal is to read back the last line the dev. board sends back.

E.G

设置ATT = 7 --- >> \发送给dev.板

Set ATT = 7 --->> \sent to dev. board

开发.董事会答复

O.K< ----- \从开发人员处收到.板

O.K <----- \ received from dev. board

发送下一行代码.

E.R.R

再次发送"set att = 7"命令.

send "set att = 7" command again.

到目前为止,我已经完成了大部分需要工作的工作.我只是无法让Delphi读取tmemo的最后一行.

So far, I've got most of what I need working. I just can't get Delphi to read the last line of the tmemo.

我尝试过

procedure TReaderProgrammer.Button3Click(Sender: TObject );
var 
  RxData : string; 
  LL : string; 
  ll2: system.integer;
begin
  LL:= memorxdata.lines.count.ToHexString;
  LL2:=memorxdata.Lines.Count;
  if ComPort1.Connected then
  begin
     showmessage(ll);
     ComPort1.WriteStr(memorxdata.Lines[ll2]+#13+#10);
  end;
end;

该showmessage仅用于我自己的参考...我知道它会将收到的数据重新弹回以供参考.

The showmessage is only there for my own reference... I know it's bouncing the data it receives back again just for reference.

奇怪的是,有时它可以工作,而且行. Count有时还会反弹回字母,所以我想我要用一种完全错误的方式来解决这个问题……

The odd thing is it works sometimes, and that lines. Count bounces back letters sometimes as well so I think I'm going about this the complete wrong way...

推荐答案

您正在阅读MemoRxData.Lines的结尾,因为它是从零开始的:

You're reading past the end of MemoRxData.Lines, as it's zero-based:

ll2 := MemoRxData.Lines.Count - 1;

ComPort1.WriteStr(MemoRxData.Lines[ll2] + #13#10;

(您的变量名很糟糕,顺便说一句.ll2简直太可怕了.您应该使用有意义且易于阅读的变量名,而不要使用这些可怕的快捷方式.)

(Your variable names are terrible, BTW. ll2 is simply horrendous to read. You should use meaningful, easy to read variable names instead of such terrible shortcuts.)

这篇关于在delphi中读取Tmemo的最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆