Solved

TRichEdit - problem with last line

Posted on 2009-04-01
6
329 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
  • 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

830 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