Solved

Scrolling a Memo by 5 lines using code

Posted on 1997-08-31
3
275 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
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now