Solved

TRichEdit - problem with last line

Posted on 2009-04-01
6
335 Views
Last Modified: 2012-05-06
Hi

I have an annoying issue with TRichEdit. I'm not sure how to solve it.

I have a TRichEdit control and the size is h:60 w:240. this should be enough for 4 lines of text.

I execute:

RE.Lines.Add('1');
RE.Lines.Add('2222 2222 222 222 2 2222 222222 2222 2222 222222 22222222 222 2222');
RE.Lines.Add('4');

this means it should extend '222...' into 2 lines, which it does correctly, due to width of control.
The problem is that after inserting '4' into 4th line, it creates NEW LINE! and now it moves all lines up so the first line is not visible anymore! Obviously with new line, there are now 5 lines.

So, instead of :

1
22222 2.2.2....
2222...
4

I see:

2222 22.2...
2222...
4
(and new empty line)

Because of new empty line the first line gest pushed up (out of the visible area).

I can move up I can get the first line to appear in control, but I would like to have it visible from the beginning.

So, it appears that:

RE.Lines.Add('...');

ads new line after the inserted line.

How can I avoid this?

Thank you
0
Comment
Question by:Delphi_developer
[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
  • 2
6 Comments
 
LVL 21

Accepted Solution

by:
developmentguru earned 125 total points
ID: 24041610
I ran your example in Delphi 2007 on windows XP and it worked fine.  I did clear it before adding the first line if that makes a difference.  I tried just setting one button to always add a line and never could get it to scroll.  One thing you could try is adding the following line to your code after the line that adds to the Rich Edit.

SendMessage(WM_SETSCROLLPOS, RichEdit1.Handle, 0, 0);

This should tell the control to scroll to position 0 (top).

Let me know if it helps.

P.S.  if you can't find the constant for WM_SETSCROLLPOS I found a reference that stets the value to WM_USER + 222.
0
 
LVL 14

Expert Comment

by:SteveBay
ID: 24041611
You could scroll the Richedit in your program with something like this:
RE.perform(WM_VSCROLL,MakeWParam(SB_THUMBPOSITION,0)  ,0);

Open in new window

0
 
LVL 14

Expert Comment

by:SteveBay
ID: 24041623
developmentguru. You beat me by mere seconds. :)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Delphi_developer
ID: 24043025
Thank you, that works.

But, why is this happening? I'm attaching a screenshot of example in completely new project, and you can see that it creates new line and puts the cursor in it, pushing line with '1' up.

I would rather fix why is this happening than using your suggestions, if possible.

Thanx.
richedit-issue.jpg
0
 
LVL 14

Assisted Solution

by:SteveBay
SteveBay earned 125 total points
ID: 24043677
This behavior is caused by the Richedit trying to put the cursor in view. Richedit only have a cursor when it has focus. If remove the focus from the Richedit while populating the lines you will avoid this issue.

     Button1.SetFocus;
     RichEdit1.Clear;
     RichEdit1.Lines.Add('1');
     RichEdit1.Lines.Add('22222 2222222222222222222222222222222.2.2....');
     RichEdit1.Lines.Add('4');
     RichEdit1.SetFocus;

Open in new window

0
 

Author Closing Comment

by:Delphi_developer
ID: 31565412
Thank you, both. I awarded both suggestions, because I might use one of the other, depending if I will ever need to focus the RichEdit or not and focus another control to avoid this issue.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month5 days, 19 hours left to enroll

627 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