Board index » delphi » TMemo scrolling problem

TMemo scrolling problem

I use a TMemo to display a dynamically updated session log.  I would
like
the text to scroll so that the latest entry is always visible.  In
Visual
Basic I use a TextBox like this with the code:

  SessionLog.text = SessionLog.text & str & vbCrLf
  SessionLog.SelStart = Len(SessionLog.text)

Setting SelStart to the end of the text scrolls the last line into view.

In Delphi, I tried the code:

  SessionLog.Text     := SessionLogMemo.Text + str + #13#10;
  SessionLog.SelStart := Length(SessionLogMemo.Text);

The new text is added but the TMemo does not scroll.  I consulted
various
FAQs and Delphi Tip sheets which suggested using PostMessage() with
WM_VSCROLL, so I added:

  PostMessage(SessionLog.Handle, WM_VSCROLL, SB_BOTTOM, 0);

This does nothing!  Then I tried SB_PAGEDOWN, which works, but only for
a
while.  Eventually, the scrolling fails to keep up and the last line
moves
further and further out of the window.  I tried several other SB_XXXXXX
parameters without success.  If I stop the session, the scroll bars work
properly.

Any ideas?

I'm using Delphi 4, build 5.104 Update pack 2 with Win NT 4.0 build 1381
SP3.

 

Re:TMemo scrolling problem


I use a TMemo to display a dynamically updated session log.  I would
like
the text to scroll so that the latest entry is always visible.  In
Visual
Basic I use a TextBox like this with the code:

  SessionLog.text = SessionLog.text & str & vbCrLf
  SessionLog.SelStart = Len(SessionLog.text)

Setting SelStart to the end of the text scrolls the last line into view.

In Delphi, I tried the code:

  SessionLog.Text     := SessionLogMemo.Text + str + #13#10;
  SessionLog.SelStart := Length(SessionLogMemo.Text);

The new text is added but the TMemo does not scroll.  I consulted
various
FAQs and Delphi Tip sheets which suggested using PostMessage() with
WM_VSCROLL, so I added:

  PostMessage(SessionLog.Handle, WM_VSCROLL, SB_BOTTOM, 0);

This does nothing!  Then I tried SB_PAGEDOWN, which works, but only for
a
while.  Eventually, the scrolling fails to keep up and the last line
moves
further and further out of the window.  I tried several other SB_XXXXXX
parameters without success.  If I stop the session, the scroll bars work
properly.

Any ideas?

I'm using Delphi 4, build 5.104 Update pack 2 with Win NT 4.0 build 1381
SP3.

Re:TMemo scrolling problem


I use a TMemo to display a dynamically updated session log.  I would
like
the text to scroll so that the latest entry is always visible.  In
Visual
Basic I use a TextBox like this with the code:

  SessionLog.text = SessionLog.text & str & vbCrLf
  SessionLog.SelStart = Len(SessionLog.text)

Setting SelStart to the end of the text scrolls the last line into view.

In Delphi, I tried the code:

  SessionLog.Text     := SessionLogMemo.Text + str + #13#10;
  SessionLog.SelStart := Length(SessionLogMemo.Text);

The new text is added but the TMemo does not scroll.  I consulted
various
FAQs and Delphi Tip sheets which suggested using PostMessage() with
WM_VSCROLL, so I added:

  PostMessage(SessionLog.Handle, WM_VSCROLL, SB_BOTTOM, 0);

This does nothing!  Then I tried SB_PAGEDOWN, which works, but only for
a
while.  Eventually, the scrolling fails to keep up and the last line
moves
further and further out of the window.  I tried several other SB_XXXXXX
parameters without success.  If I stop the session, the scroll bars work
properly.

Any ideas?

I'm using Delphi 4, build 5.104 Update pack 2 with Win NT 4.0 build 1381
SP3.

Re:TMemo scrolling problem


I use a TMemo to display a dynamically updated session log.  I would
like
the text to scroll so that the latest entry is always visible.  In
Visual
Basic I use a TextBox like this with the code:

  SessionLog.text = SessionLog.text & str & vbCrLf
  SessionLog.SelStart = Len(SessionLog.text)

Setting SelStart to the end of the text scrolls the last line into view.

In Delphi, I tried the code:

  SessionLog.Text     := SessionLogMemo.Text + str + #13#10;
  SessionLog.SelStart := Length(SessionLogMemo.Text);

The new text is added but the TMemo does not scroll.  I consulted
various
FAQs and Delphi Tip sheets which suggested using PostMessage() with
WM_VSCROLL, so I added:

  PostMessage(SessionLog.Handle, WM_VSCROLL, SB_BOTTOM, 0);

This does nothing!  Then I tried SB_PAGEDOWN, which works, but only for
a
while.  Eventually, the scrolling fails to keep up and the last line
moves
further and further out of the window.  I tried several other SB_XXXXXX
parameters without success.  If I stop the session, the scroll bars work
properly.

Any ideas?

I'm using Delphi 4, build 5.104 Update pack 2 with Win NT 4.0 build 1381
SP3.

Re:TMemo scrolling problem


I use a TMemo to display a dynamically updated session log.  I would
like
the text to scroll so that the latest entry is always visible.  In
Visual
Basic I use a TextBox like this with the code:

  SessionLog.text = SessionLog.text & str & vbCrLf
  SessionLog.SelStart = Len(SessionLog.text)

Setting SelStart to the end of the text scrolls the last line into view.

In Delphi, I tried the code:

  SessionLog.Text     := SessionLogMemo.Text + str + #13#10;
  SessionLog.SelStart := Length(SessionLogMemo.Text);

The new text is added but the TMemo does not scroll.  I consulted
various
FAQs and Delphi Tip sheets which suggested using PostMessage() with
WM_VSCROLL, so I added:

  PostMessage(SessionLog.Handle, WM_VSCROLL, SB_BOTTOM, 0);

This does nothing!  Then I tried SB_PAGEDOWN, which works, but only for
a
while.  Eventually, the scrolling fails to keep up and the last line
moves
further and further out of the window.  I tried several other SB_XXXXXX
parameters without success.  If I stop the session, the scroll bars work
properly.

Any ideas?

I'm using Delphi 4, build 5.104 Update pack 2 with Win NT 4.0 build 1381
SP3.

Re:TMemo scrolling problem


I use a TMemo to display a dynamically updated session log.  I would
like
the text to scroll so that the latest entry is always visible.  In
Visual
Basic I use a TextBox like this with the code:

  SessionLog.text = SessionLog.text & str & vbCrLf
  SessionLog.SelStart = Len(SessionLog.text)

Setting SelStart to the end of the text scrolls the last line into view.

In Delphi, I tried the code:

  SessionLog.Text     := SessionLogMemo.Text + str + #13#10;
  SessionLog.SelStart := Length(SessionLogMemo.Text);

The new text is added but the TMemo does not scroll.  I consulted
various
FAQs and Delphi Tip sheets which suggested using PostMessage() with
WM_VSCROLL, so I added:

  PostMessage(SessionLog.Handle, WM_VSCROLL, SB_BOTTOM, 0);

This does nothing!  Then I tried SB_PAGEDOWN, which works, but only for
a
while.  Eventually, the scrolling fails to keep up and the last line
moves
further and further out of the window.  I tried several other SB_XXXXXX
parameters without success.  If I stop the session, the scroll bars work
properly.

Any ideas?

I'm using Delphi 4, build 5.104 Update pack 2 with Win NT 4.0 build 1381
SP3.

Re:TMemo scrolling problem


I use a TMemo to display a dynamically updated session log.  I would
like
the text to scroll so that the latest entry is always visible.  In
Visual
Basic I use a TextBox like this with the code:

  SessionLog.text = SessionLog.text & str & vbCrLf
  SessionLog.SelStart = Len(SessionLog.text)

Setting SelStart to the end of the text scrolls the last line into view.

In Delphi, I tried the code:

  SessionLog.Text     := SessionLogMemo.Text + str + #13#10;
  SessionLog.SelStart := Length(SessionLogMemo.Text);

The new text is added but the TMemo does not scroll.  I consulted
various
FAQs and Delphi Tip sheets which suggested using PostMessage() with
WM_VSCROLL, so I added:

  PostMessage(SessionLog.Handle, WM_VSCROLL, SB_BOTTOM, 0);

This does nothing!  Then I tried SB_PAGEDOWN, which works, but only for
a
while.  Eventually, the scrolling fails to keep up and the last line
moves
further and further out of the window.  I tried several other SB_XXXXXX
parameters without success.  If I stop the session, the scroll bars work
properly.

Any ideas?

I'm using Delphi 4, build 5.104 Update pack 2 with Win NT 4.0 build 1381
SP3.

Re:TMemo scrolling problem


I use a TMemo to display a dynamically updated session log.  I would
like the text to scroll so that the latest entry is always visible.  In
Visual Basic I use a TextBox like this with the code:

  SessionLog.text = SessionLog.text & str & vbCrLf
  SessionLog.SelStart = Len(SessionLog.text)

Setting SelStart to the end of the text scrolls the last line into view.

In Delphi, I tried the code:

  SessionLog.Text     := SessionLogMemo.Text + str + #13#10;
  SessionLog.SelStart := Length(SessionLogMemo.Text);

The new text is added but the TMemo does not scroll.  I consulted
various FAQs and Delphi Tip sheets which suggested using PostMessage()
with WM_VSCROLL, so I added:

  PostMessage(SessionLog.Handle, WM_VSCROLL, SB_BOTTOM, 0);

This does nothing!  Then I tried SB_PAGEDOWN, which works, but only for
a while.  Eventually, the scrolling fails to keep up and the last line
moves further and further out of the window.  I tried several other
SB_XXXXX parameters without success.  If I stop the session, the scroll
bars work properly.

Any ideas?

I'm using Delphi 4, build 5.104 Update pack 2 with Win NT 4.0 build 1381
SP3.

Re:TMemo scrolling problem


I use a TMemo to display a dynamically updated session log.  I would
like the text to scroll so that the latest entry is always visible.  In
Visual Basic I use a TextBox like this with the code:

  SessionLog.text = SessionLog.text & str & vbCrLf
  SessionLog.SelStart = Len(SessionLog.text)

Setting SelStart to the end of the text scrolls the last line into view.

In Delphi, I tried the code:

  SessionLog.Text     := SessionLogMemo.Text + str + #13#10;
  SessionLog.SelStart := Length(SessionLogMemo.Text);

The new text is added but the TMemo does not scroll.  I consulted
various FAQs and Delphi Tip sheets which suggested using PostMessage()
with WM_VSCROLL, so I added:

  PostMessage(SessionLog.Handle, WM_VSCROLL, SB_BOTTOM, 0);

This does nothing!  Then I tried SB_PAGEDOWN, which works, but only for
a while.  Eventually, the scrolling fails to keep up and the last line
moves further and further out of the window.  I tried several other
SB_XXXXX parameters without success.  If I stop the session, the scroll
bars work properly.

Any ideas?

I'm using Delphi 4, build 5.104 Update pack 2 with Win NT 4.0 build 1381
SP3.

Re:TMemo scrolling problem


I use a TMemo to display a dynamically updated session log.  I would
like the text to scroll so that the latest entry is always visible.  In
Visual Basic I use a TextBox like this with the code:

  SessionLog.text = SessionLog.text & str & vbCrLf
  SessionLog.SelStart = Len(SessionLog.text)

Setting SelStart to the end of the text scrolls the last line into view.

In Delphi, I tried the code:

  SessionLog.Text     := SessionLogMemo.Text + str + #13#10;
  SessionLog.SelStart := Length(SessionLogMemo.Text);

The new text is added but the TMemo does not scroll.  I consulted
various FAQs and Delphi Tip sheets which suggested using PostMessage()
with WM_VSCROLL, so I added:

  PostMessage(SessionLog.Handle, WM_VSCROLL, SB_BOTTOM, 0);

This does nothing!  Then I tried SB_PAGEDOWN, which works, but only for
a while.  Eventually, the scrolling fails to keep up and the last line
moves further and further out of the window.  I tried several other
SB_XXXXX parameters without success.  If I stop the session, the scroll
bars work properly.

Any ideas?

I'm using Delphi 4, build 5.104 Update pack 2 with Win NT 4.0 build 1381
SP3.

Re:TMemo scrolling problem


Hi,

I had same problem. Here is the solution:

     SendMessage (SessionLog.Handle,EM_ScrollCaret,0,0);

                            -Dodo-

Quote

Re:TMemo scrolling problem


Quote
David Tiktin (tik...@AdvancedRelay.com) wrote:

: I use a TMemo to display a dynamically updated session log.  I would
: like the text to scroll so that the latest entry is always visible.  In
: Visual Basic I use a TextBox like this with the code:

:   SessionLog.text = SessionLog.text & str & vbCrLf
:   SessionLog.SelStart = Len(SessionLog.text)

: Setting SelStart to the end of the text scrolls the last line into view.

: In Delphi, I tried the code:

:   SessionLog.Text     := SessionLogMemo.Text + str + #13#10;
:   SessionLog.SelStart := Length(SessionLogMemo.Text);

: The new text is added but the TMemo does not scroll.  I consulted
: various FAQs and Delphi Tip sheets which suggested using PostMessage()
: with WM_VSCROLL, so I added:

:   PostMessage(SessionLog.Handle, WM_VSCROLL, SB_BOTTOM, 0);

: This does nothing!  Then I tried SB_PAGEDOWN, which works, but only for
: a while.  Eventually, the scrolling fails to keep up and the last line
: moves further and further out of the window.  I tried several other
: SB_XXXXX parameters without success.  If I stop the session, the scroll
: bars work properly.

: Any ideas?

: I'm using Delphi 4, build 5.104 Update pack 2 with Win NT 4.0 build 1381
: SP3.

Hello. You can use the Append() method of TMemo. This should insert your
string at the bottom of your memo box and will always keep this message
(ie. show) in view. Just watch out if for too many Appends since TMemo has
a size limit.  

I keep about 1000 lines in the memo box and if more lines come in, I just
start removing the earliest lines out the memo box. This works nicely in
Delphi 3.

--
"Two wrongs don't make a right, but three lefts do."   - rec.humor

Joseph Eng  [j...@ripco.com]           Support Hudson Leick!

Re:TMemo scrolling problem


In article <37446464.2D0E6...@AdvancedRelay.com>, David Tiktin

Quote
<tik...@AdvancedRelay.com> writes:
>I use a TMemo to display a dynamically updated session log.  I would
>like
>the text to scroll so that the latest entry is always visible.  In
>Visual
>Basic I use a TextBox like this with the code:

>  SessionLog.text = SessionLog.text & str & vbCrLf
>  SessionLog.SelStart = Len(SessionLog.text)

>Setting SelStart to the end of the text scrolls the last line into view.

>In Delphi, I tried the code:

>  SessionLog.Text     := SessionLogMemo.Text + str + #13#10;
>  SessionLog.SelStart := Length(SessionLogMemo.Text);

>The new text is added but the TMemo does not scroll.  I consulted
>various
>FAQs and Delphi Tip sheets which suggested using PostMessage() with
>WM_VSCROLL, so I added:

>  PostMessage(SessionLog.Handle, WM_VSCROLL, SB_BOTTOM, 0);

>This does nothing!  Then I tried SB_PAGEDOWN, which works, but only for
>a
>while.  Eventually, the scrolling fails to keep up and the last line
>moves
>further and further out of the window.  I tried several other SB_XXXXXX
>parameters without success.  If I stop the session, the scroll bars work
>properly.

This is a note I produced on TMemo scrolling. Note that some of the methods
work only if the TMemo has focus.
.
==========================
TMemo and Scrolling

If you just add lines to the TMemo (without BeginUpdate / EndUpdate), the
viewport scrolls to the last line added. However if you use BeginUpdate / add
lines / EndUpdate, then the viewport does not scroll.
If you want to position the viewport, you can then use the windows messages in
a Perform method to move the viewport. Some of the messages (with their
parameters) available are :-
(EM_Scroll, nScroll, 0) scrolls an amount defined by the second parameter
constant, the third parameter must be zero.
  where nScroll is one of the constants SB_LINEDOWN, SB_LINEUP, SB_PAGEDOWN, or
SB_PAGEUP. The move is limited to those available, ie it does not scroll so
that the first or the last line is out of the viewport.

(EM_LineScroll, cxScroll, cyScroll)
  where cxScroll and cyScroll are integers (+ve or -ve) to scroll characters
(cxScroll) or lines (cyScroll). The line move is limited to those available.

(EM_ScrollCaret, 0, 0) moves the viewport so that the caret is in the viewport.
  where the second and third parameters must be zero.

Memo1.Perform(EM_SetSel, 0, 0); {move caret to top}
Memo1.Perform(EM_LineScroll, 0, Memo1.Lines.Count * -1); {move to top}
{or Memo1.Perform(EM_ScrollCaret, 0, 0); scroll caret into view}
Memo1.SetFocus;

Memo1.Perform(EM_SetSel, Memo1.GetTextLen, Memo1.GetTextLen); {move caret to
bottom}
Memo1.Perform(EM_LineScroll, 0, Memo1.Lines.Count); {move to bottom}
{or Memo1.Perform(EM_ScrollCaret, 0, 0);  scroll caret into view}
Memo1.SetFocus;

==========================

Alan Lloyd
alangll...@aol.com

Other Threads