autoscrolling memo in delphi
Asked Answered
M

7

12

Does delphi contain a component that allows auto scroll text loaded from db, like in news sites?

Tt's for a delphi 7 application and requires a vertical scrolling.

Malonylurea answered 1/12, 2010 at 9:24 Comment(1)
The answer from @vcldeveloper is best, but another option to consider is simply to add lines to the TMemo (or similar) VCL control in reverse order. This puts the latest item on top which may remove the need to scroll at all.Swore
P
7

None of those solutions for scrolling worked for me in the RichEdit memo. Using Delphi 2010 + w7. But this one works perfectly:

After every Lines.Add('...') this follows:

SendMessage(RichEditMemo.Handle, WM_VSCROLL, SB_LINEDOWN, 0);

Found in: http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_10120212.html

Polygamist answered 18/11, 2014 at 15:13 Comment(0)
A
47

For such a simple task, you don't need to buy a commercial component! All you need to do is to send an EM_LINESCROLL message to that memo control, to make it scroll to the last line:

procedure ScrollToLastLine(Memo: TMemo);
begin
  SendMessage(Memo.Handle, EM_LINESCROLL, 0,Memo.Lines.Count);
end;

If your memo is read-only to users and is updated automatically by the application, you can put a call to the above procedure in its OnChange event-handler, so that whenever the text inside the memo is changed, it is automatically scrolled down to the last line.

Athabaska answered 1/12, 2010 at 15:51 Comment(5)
Hmm, That shorter than mine, Memo_Scroll Golf anyone? :)Sevenfold
this scroll is way to fast. how do slow it down?Malonylurea
@none, what do you mean by slowing it down? Are you going to make a visual effect of scrolling?Athabaska
yea, some kind. like news flash scrolling memo.Malonylurea
So don't want a scrolling memo at all... You need to paint the text onto a TPaintbox and then slowly scroll the painting position :)Sevenfold
P
7

None of those solutions for scrolling worked for me in the RichEdit memo. Using Delphi 2010 + w7. But this one works perfectly:

After every Lines.Add('...') this follows:

SendMessage(RichEditMemo.Handle, WM_VSCROLL, SB_LINEDOWN, 0);

Found in: http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_10120212.html

Polygamist answered 18/11, 2014 at 15:13 Comment(0)
S
5

Possibly, to save you some money you could adapt this to scroll a DBMemo:

EchoMemo.Lines.Add('A Line of text or more');
EchoMemo.SelStart := EchoMemo.GetTextLen;
EchoMemo.SelLength := 0;
EchoMemo.ScrollBy(0, EchoMemo.Lines.Count);
EchoMemo.Refresh;

I use for a log display.

Sevenfold answered 1/12, 2010 at 15:46 Comment(0)
G
5

You can also use Memo.GoToTextEnd; when needed, for example inside an onchange event. Is not a proper auto-scrolling effect but can be useful in similar situations.

Giulia answered 28/1, 2018 at 17:51 Comment(2)
Note - this apparently for FMX, not older VCL appsInvolved
This solution works perfectly in Fire MonkeyAllies
C
3

The right thing to send messages within the same application is to use the Perform command, SendMessage sends it to the windows stream while perform sends it directly to the component. So much so that he doesn't even ask for the handle:

memo1.Perform(WM_VSCROLL, SB_LINEDOWN, 0);

Carreno answered 22/4, 2021 at 16:6 Comment(1)
SB_LINEDOWN scrolls one line down, so you have to know how many times to call it to scroll enough. The answer with EM_LINESCROLL scrolls to the end with just one call.Sanjak
T
1

If you're working with DevExpress components, you should use InnerControl->Handle. So it should look like this:

SendMessage(cxMemo->InnerControl->Handle, EM_LINESCROLL, 0,cxMemo->Lines->Count);
Tieshatieup answered 17/12, 2018 at 14:57 Comment(0)
D
0

More generally regarding the need to scroll a TControl (can be a TMemo) to a specific position, here is what says the official RAD Studio /Delphi documentation as an example of usage of TControl.Perform

=> use the Perform(EM_SCROLLCARET, 0, 0) method

Derbent answered 12/7, 2022 at 10:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.