Reading the last line in a Tmemo in delphi

跟風遠走 提交于 2020-01-16 18:06:11

问题


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

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

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

Dev. Board replies

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

send next line of code.

Or

E.R.R

send "set att = 7" command again.


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.

I have tried

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;

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

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...


回答1:


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;

(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.)



来源:https://stackoverflow.com/questions/26811784/reading-the-last-line-in-a-tmemo-in-delphi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!