Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Scrolling a Memo by 5 lines using code

Posted on 1997-08-31
3
Medium Priority
?
289 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 100 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

715 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