Solved

Speedup Richedit copy

Posted on 2000-02-23
7
409 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

Industry Leaders: 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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
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 …

691 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