• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 825
  • Last Modified:

No Scrolling in RichEdit

In RichEdit, I would like to keep whole text no scrolling when it is updated. How should I do.
0
ysimon
Asked:
ysimon
  • 6
  • 5
  • 4
  • +2
1 Solution
 
EpsylonCommented:
What do you mean with 'updated'?
0
 
d32coderCommented:
I know what he means..

In the RichEdit as with TMemo, when you programatically dump alot of text in the box the cursor goes to the end.
I believe he wants to reposition the cursor to it's original spot.

FROM THE HELP FILE
Read SelStart ...
If there is no selected text, SelStart indicates the position of the cursor. Set SelStart to remove the current selection and position the cursor just before the indicated character.

Try this ...

Richedit1.loadfromfile(blah.rtf');
Richedit1.SelStart := 0;


0
 
d32coderCommented:
Um...

Richedit1.loadfromfile(blah.rtf');
Richedit1.SelStart := 0;
RichEdit1.SelLength := 0; // avoid selecting text

Don
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
ysimonAuthor Commented:
The text in RichEdit was written via a set of RichEdit1.Lines.Append('Text');
Another Update button will reload that set of RichEdit1.Lines.Append('Text');

Each time, it will go to the last line. I would like to keep the current viewing position. Is that possible?

ysimon
0
 
edeyCommented:
I would add to the above:

with richEdit1.lines do
begin
 beginUpdate;
 append('text');
 selStart := 0;
 endUpdate;
end;

This way there is no rawing done until everything is finalized.

GL
Mike
0
 
d32coderCommented:

procedure addtext();
var cpos: integer;
 with Richedit1 do
  begin
  cpos := selstart; // get starting position
  Lines.Append('Text'); // add text
  SelStart := cpos; //reset starting position
  SelLength := 0; // no selected text when finished.
  end;
end;

** Edey: I trust that is important but I'm still kinda new, what might happen?

Don
0
 
d32coderCommented:

procedure addtext();
var cpos: integer;
 with Richedit1 do
  begin
  cpos := selstart; // get starting position
  Lines.Append('Text'); // add text
  SelStart := cpos; //reset starting position
  SelLength := 0; // no selected text when finished.
  end;
end;

** Edey: I trust that is important but I'm still kinda new, what might happen?

Don
0
 
d32coderCommented:
um, don't refresh after posting :)

ALSO note that there shouls be a ; after the

var cpos: integer;

The comma snuck in there.

Don
0
 
ysimonAuthor Commented:
Have you tried

procedure addtext();
var cpos, I: integer;
with Richedit1 do
 begin
 cpos := selstart; // get starting position

 for I:=1 to 100 do
 Lines.Append('Text'); // add text

 SelStart := cpos; //reset starting position
 SelLength := 0; // no selected text when finished.
 end;
end;
0
 
edeyCommented:
I'm not sure what you mean, but if you're referring to the beginUpdate/endUpdate - well, nothing much happens if you don't have them.  The only thing they do is keep the control from updating when you mess with it's lines proeprty.  This way if you make alot of changes it doesn't waste time redrawing things a thousand times over.  Try something like this:

for ix := 0 to 10000 do
 memo1.text := memo1.text + chr(ord('a')+random(26));

then try it like so:

memo1.lines.beginUpdate;
for ix := 0 to 10000 do
 memo1.text := memo1.text + chr(ord('a')+random(26));
memo1.lines.endUpdate;

all these do is fill a memo with 10000 random a's, b's, c's etc.  The second, though, will be _much_ faster with -alot_ less flicker.

Your example prob. doesn't require such a speed optimization but the code does have a side benifit.  Because the control doesn't get all those extra updates no one can see the text get added, the memo scroll to the end, then scroll back up again (when you set selStart) - it'll look a lot cleaner.

GL
Mike
0
 
d32coderCommented:
Sweet.  Thanks for the tip  :)
0
 
edeyCommented:
Glad to be of service :)

GL
Mike
0
 
ysimonAuthor Commented:
If using

memo1.lines.beginUpdate;
memo1.Lines.Clear;
for ix := 0 to 1000 do
memo1.Lines.Append(chr(ord('a')+random(26));
memo1.lines.endUpdate;

Can it stop at the current viewing position?

ysimon

0
 
edeyCommented:
Yup, the logic is the same as before:

memo1.lines.beginUpdate;
startPos := memo1.selStart;
for ix := 0 to 1000 do
memo1.Lines.Append(chr(ord('a')+random(26));
memo1.selStart := startPos;
memo1.lines.endUpdate;

GL
Mike
0
 
ysimonAuthor Commented:
Yes, you are right.
In my case, it always goes to the end after For Loop.
I have to find why.

ysimon
0
 
ysimonAuthor Commented:
I found why it always go to end. Because I set vertical scollbar. If set to None, like your example, it will stay at beginning. Any suggestion?

ysimon
0
 
MoondancerCommented:
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if still open in seven days.  Please post closing recommendations before that time.

Question(s) below appears to have been abandoned. Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you. You must tell the participants why you wish to do this, and allow for Expert response.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question. Again, please comment to advise the other participants why you wish to do this.

For special handling needs, please post a zero point question in the link below and include the question QID/link(s) that it regards.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click the Help Desk link on the left for Member Guidelines, Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Please click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues, to track all your open and locked questions at this site.  If you are an EE Pro user, use the Power Search option to find them.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.11866558.html
http://www.experts-exchange.com/questions/Q.20107980.html
http://www.experts-exchange.com/questions/Q.20112507.html
http://www.experts-exchange.com/questions/Q.20121203.html
http://www.experts-exchange.com/questions/Q.20122370.html
http://www.experts-exchange.com/questions/Q.20128022.html
http://www.experts-exchange.com/questions/Q.20128024.html
http://www.experts-exchange.com/questions/Q.20143035.html
http://www.experts-exchange.com/questions/Q.20145949.html
http://www.experts-exchange.com/questions/Q.20164917.html
http://www.experts-exchange.com/questions/Q.20164983.html
http://www.experts-exchange.com/questions/Q.20171798.html
http://www.experts-exchange.com/questions/Q.20179154.html
http://www.experts-exchange.com/questions/Q.20192667.html
http://www.experts-exchange.com/questions/Q.20192583.html
http://www.experts-exchange.com/questions/Q.20200806.html
http://www.experts-exchange.com/questions/Q.20201786.html
http://www.experts-exchange.com/questions/Q.20201947.html
http://www.experts-exchange.com/questions/Q.20246959.html
http://www.experts-exchange.com/questions/Q.20252474.html
http://www.experts-exchange.com/questions/Q.20259886.html
http://www.experts-exchange.com/questions/Q.20270462.html
http://www.experts-exchange.com/questions/Q.20273241.html


To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20265181.html
http://www.experts-exchange.com/questions/Q.20277546.html

PLEASE DO NOT AWARD THE POINTS TO ME.  
 
------------>  EXPERTS:  Please leave any comments regarding your closing recommendations if this item remains inactive another seven (7) days.  Also, if you are interested in the cleanup effort, please click this link http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange

P.S.  For any year 2000 questions, special attention is needed to ensure the first correct response is awarded, since they are not in the comment date order, but rather in Member ID order.
0
 
MoondancerCommented:
Zero response from anyone, finalized.
Moondancer - EE Moderator
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 6
  • 5
  • 4
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now