Solved

Speedup Richedit copy

Posted on 2000-02-23
7
396 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
  • 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

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

Suggested Solutions

Title # Comments Views Activity
Need Help Delphi 2010 CheckBox1 Stored value in memo 13 70
Delphi...Split view - idea? 1 88
update joined tables 2 55
Wincontrol not (correctly) drawn 15 40
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 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