• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

Scrolling a Memo by 5 lines using code

I want to scroll a memo component to a particular line, say, line 5 -
and when I try


I get the text scrolling (but not by a complete line - so I get a blur
effect).  Obviously I need to replace the 10 by the font height in
pixels (multiplied by the number of lines to scroll by).

But the problem seems deeper - when I do a
the effect of the scroll goes away viz. the scroll has not 'really'
happened - it is just a visual illusion.

I obviously need to send a EM_ message of some sort, and found the
following routine which I experimentally HACKED:

procedure ScrollMemoToTop(Memo: TCustomMemo);
  topLine : integer;
  topLine := SendMessage(Memo.Handle, EM_GETFIRSTVISIBLELINE,
     0, 0);
  // Experimentally override with the line to scroll to
  topLine := 5;
  SendMessage(Memo.Handle, EM_LINESCROLL,
      0, MAKELONG(word(-topLine),0));

But this doesn't seem to actually do anything.  Can anyone help me out
here?  I just want to be able to simply say

Andy Bulka
WindowWare Multimedia

1 Solution
When you scroll to line 5 you want to see it as the first line displayed in the memo?
You'r code work's fine but you'r memo probably don't have enought lines.

{from HelpFile}

The edit control does not scroll vertically past the last line of text in the edit control. If the current line plus the number of lines specified by the cyScroll parameter exceeds the total number of lines in the edit control, the value is adjusted so that the last line of the edit control is scrolled to the top of the edit-control window.
{End of help comment}

I try form with memo. i fill memo with 20lines, pace button on form and write procedure :

procedure TForm1.Button1Click(Sender: TObject);
  lkLines : integer;
  lkLines := 5;
  SendMessage(Memo1.Handle, EM_LINESCROLL, 0, MAKELONG(word(lkLines),0));

This work's fine. in You'r code You call -lkLines so i think you need scroll in different way ?

OK i do this too but you must have lines to scroll.

abulkaAuthor Commented:
Thanks.  The actual problem in my code was the minus sign

SendMessage(Memo.Handle, EM_LINESCROLL,
                     0, MAKELONG(word(-topLine),0));

which should have been removed.  I'm not sure why the original code I based the algorithm on had it there.  Anyway - problem fixed.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now