Board index » delphi » Adding strings to TMemo

Adding strings to TMemo

Hi,

I'm receving text strings from the serial port and once each line is
complete adding it into a TMEMO object COMTraffic.  That works fine
until I have more lines than fit into the form window.  I have the
vertical scroll bars enabled and the lines are properly added into the
TMEMO object and show up on the screen.  But,  as the list of lines
gets longer, after each 'add' the scroll bar is repositioned to the
front of the TMEMO list.  I'd like to keep it at the end of the list
so I can see the most recently added strings.

Has anyone any suggestions?  One would think this would be simple but
I can't find anything in the help and setting COMTraffic.Selstart to
Length(ComTraffic.Text) does't seem to work.

Thanks,

John Dammeyer

 

Re:Adding strings to TMemo


I've com eup with a solution but if there's a more elegant way I'd
sure like to see it.

After a COMTraffic.Lines.Add(InputBuffer) I test to see if I've
exceeded the maxium number of lines I want to retain.  If so I delete
the oldest lines.  That puts the first n lines back on the form.  Any
further adds done't move me to the bottom of the list because the last
operation is always the delete.  So then I selected the last character
of the text and that puts the window into the memo back to the bottom.

  while COMTraffic.Lines.Count > 100 do COMTraffic.lines.Delete(0);
  COMTraffic.SelStart := Length(COMTraffic.text)-2;
  COMTraffic.SelLength := 1;

So it appears there is a persistance and no direct way to specify a
GotToEndOfScreen type method or property.

The simple solution was to delete any lines that exceed my buffer size
first,  and then get the characters from the serial port and do the
COMTraffic.Lines.add(InputBuffer).  That leaves the end of the TMemo
displayed.

I've been looking through the Delphi Library code but can't see any
shortcut to just GotoEndoftext.

Suggestions?

Thanks.

John

Quote
jo...@autoartisans.com (John Dammeyer) wrote:
>Hi,

>I'm receving text strings from the serial port and once each line is
>complete adding it into a TMEMO object COMTraffic.  That works fine
>until I have more lines than fit into the form window.  I have the
>vertical scroll bars enabled and the lines are properly added into the
>TMEMO object and show up on the screen.  But,  as the list of lines
>gets longer, after each 'add' the scroll bar is repositioned to the
>front of the TMEMO list.  I'd like to keep it at the end of the list
>so I can see the most recently added strings.

>Has anyone any suggestions?  One would think this would be simple but
>I can't find anything in the help and setting COMTraffic.Selstart to
>Length(ComTraffic.Text) does't seem to work.

>Thanks,

>John Dammeyer

Re:Adding strings to TMemo


In article <3dc1fab3.163026...@news.telus.net>, jo...@autoartisans.com (John

Quote
Dammeyer) writes:
>So it appears there is a persistance and no direct way to specify a
>GotToEndOfScreen type method or property.

Send the Memo a scroll message ...

  Memo1.Perform(EM_LINESCROLL, 0, Memo1.Lines.count);

.. but this may leave the selection and entry-point at the (undisplayed) top of
the memo, so move the caret (insertion point) ...

  Memo1.Perform(EM_SETSEL, Memo1.GetTextLen, Memo1.GetTextLen);

.. which latter is the same as your Delphi code, but using windows API
messages.

Alan Lloyd
alangll...@aol.com

Other Threads