Hello LMD team,
I need a "terminal window" to supervise serial (RS232) ASCII data in an application that is used for data acquisition and which runs 24/7. I used to have a brilliant little component for this which was written by Danny Thorpe (it was called tConsole) but unfortunately it only works correctly on ANSI versions of Delphi so I'm looking for a replacement.
I'd like the window to respond quickly and smoothly, but I also need to minimize CPU load and flicker when data comes in. The window may be limited to show the last 200 lines or so.
I thought that maybe tLmdMemo would be suitable, because it has a possibility to hide the caret and also a beginupdate/endupdate method to reduce flicker and CPU load, but I have the impression that beginupdate/endupdate is buggy.
The memo doesn't always scroll to the end of the text correctly after inserting. Am I doing something wrong? My text insertion method looks like this:
Comments
procedure tEventLogFrame.LogMsg (const msg: Widestring; Infolevel: Integer; Sameline: Boolean);
var
LineCount,i: Integer;
Updating:Boolean;
Procedure DoBeginUpdate;
begin
if not Updating then
begin
Updating:=True;
lmdmemo1.beginupdate;
end;
end;
Procedure DoEndUpdate;
begin
if Updating then lmdmemo1.EndUpdate;
Updating:=False;
end;
begin
Updating:=False;
if fReduceCPULoad then DoBeginUpdate;
LineCount := lmdmemo1.Lines.count;
// Either update text on last line or append one line.
if sameline then
begin
if LineCount >= 1 then
lmdmemo1.lines[LineCount-1] := msg
else
lmdmemo1.lines.add(msg);
end
else
lmdmemo1.lines.add(msg);
// Limit maximum number of lines. Delete "delta" lines at once
// to reduce cpu load and flicker.
if LineCount > fmaxlines then
begin
DoBeginUpdate;
for i := 1 to fDelta do
lmdmemo1.lines.delete(0);
end;
DoEndUpdate;
if fUseProcessMessages then
application.ProcessMessages;
end;