Solved

Speedup Richedit copy

Posted on 2000-02-23
7
402 Views
Last Modified: 2013-11-22
I need to copy one richedit's lines to another one.

Richedit2.lines:=Richedit1.lines;

But if the first RE content is a bit long(60K, even)  then The cursor starts to blink uglily( :) ) and it takes alota time.

If I do the thing in this way:

for i:=0 to richedit1.lines.count-1 do
  richedit2.lines.add(richedit1.lines[i]);

It doesn't speed up anyway.....

plz help
0
Comment
Question by:duke_n
[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
  • 5
  • 2
7 Comments
 
LVL 6

Expert Comment

by:edey
ID: 2551281
what happens if you use TRichEdit.assign, or contain the copy with calls to richEdit.lines.beginUpdate/richEdit.lines.endUpdate?


GL
Mike
0
 
LVL 1

Author Comment

by:duke_n
ID: 2551338
Assign lasts the same time.
Y'know, that's weird: even the loading of the original file was MUCH faster(and it involves HDD which supposta be slower than RAM).

I don't understand whatcha mean with Begin and EndUpdate. can ya bring some code[please]?
0
 
LVL 6

Expert Comment

by:edey
ID: 2551359
the above should suggest TRichEdit.lines.assign, not TRichEdit.assign.  

Also, a quick check (using windows.pas as a test file) found that richEdit2.txt := richEdit1.text was *MUCH* faster ie.

copying lines = 14440ms
assigning lines = 14990ms
begin/end update = 14500ms
copying text = 160ms


GL
Mike
0
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!

 
LVL 6

Expert Comment

by:edey
ID: 2551380
>Assign lasts the same time.

yeah, I though it would be faster too hmmm.

>Y'know, that's weird: even the loading
>of the original file was MUCH faster
>and it involves HDD which supposta be
>slower than RAM).

I believe this is due to the control being redrawn while it is updated

>I don't understand whatcha mean with
>Begin and EndUpdate. can ya bring some
>code[please]?

the lines property (a TStrings desc) has teo methods beginUpdate & endUpdate.  If you need to make changes to the text (many insertions/deletions etc.) "bracketing" them with these two calls can significantly improve performance.


Anyway, see above comment as to the text solution


Gl
Mike
0
 
LVL 6

Accepted Solution

by:
edey earned 20 total points
ID: 2551385
this is the code i used to test the above mentioned "solutions":


procedure TForm1.Button1Click(Sender: TObject);
var
   t : TTimeStamp;
begin
     richEdit2.lines.clear;
     t := dateTimeToTimeStamp(time);
     richEdit2.lines := richEdit1.lines;
     caption := intToStr(dateTimeToTimeStamp(time).time-t.time);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
   t : TTimeStamp;
begin
     richEdit2.lines.clear;
     t := dateTimeToTimeStamp(time);
     richEdit2.lines.assign(richEdit1.lines);
     caption := intToStr(dateTimeToTimeStamp(time).time-t.time);
end;

procedure TForm1.Button3Click(Sender: TObject);
var
   t : TTimeStamp;
begin
     richEdit2.lines.clear;
     t := dateTimeToTimeStamp(time);
     richEdit2.lines.beginUpdate;
     richEdit2.lines := richEdit1.lines;
     richEdit2.lines.endUpdate;
     caption := intToStr(dateTimeToTimeStamp(time).time-t.time);
end;

procedure TForm1.Button4Click(Sender: TObject);
var
   t : TTimeStamp;
begin
     richEdit2.lines.clear;
     t := dateTimeToTimeStamp(time);
     richEdit2.text := richEdit1.text;
     caption := intToStr(dateTimeToTimeStamp(time).time-t.time);
end;



GL
Mike
0
 
LVL 1

Author Comment

by:duke_n
ID: 2554141
Now I see!!!!!

I tried to copy the RE.Lines.
I didn't see it has Re.Text.

You've been most helpful, sonny :)
0
 
LVL 6

Expert Comment

by:edey
ID: 2554670
Glad to be of service :)

GL
Mike
0

Featured Post

Independent Software Vendors: 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

Suggested Solutions

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 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