Reputation: 119
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...
Upvotes: 0
Views: 3193
Reputation: 125708
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.)
Upvotes: 6