Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Scrolling a Memo by 5 lines using code

Posted on 1997-08-31
3
Medium Priority
?
294 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 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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

971 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