Solved

Scrolling a Memo by 5 lines using code

Posted on 1997-08-31
3
281 Views
Last Modified: 2012-05-04
I want to scroll a memo component to a particular line, say, line 5 -
and when I try

     memo1.scrollby(0,10);

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
    memo1.repaint;
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);
var
  topLine : integer;
begin
  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));
end;

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

--
Andy Bulka
WindowWare Multimedia











0
Comment
Question by:abulka
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Expert Comment

by:ronit051397
ID: 1343232
When you scroll to line 5 you want to see it as the first line displayed in the memo?
0
 
LVL 3

Accepted Solution

by:
mirek071497 earned 50 total points
ID: 1343233
You'r code work's fine but you'r memo probably don't have enought lines.

{from HelpFile}
Remarks

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);
var
  lkLines : integer;
begin
  lkLines := 5;
  SendMessage(Memo1.Handle, EM_LINESCROLL, 0, MAKELONG(word(lkLines),0));
end;

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.

0
 

Author Comment

by:abulka
ID: 1343234
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.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question