abulka
asked on
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
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
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
When you scroll to line 5 you want to see it as the first line displayed in the memo?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.