richviewedit1 to richviewedit2 and richviewedit2 to richviewedit1
this is procedure very slow and some not run for after 100 pages
how can I fast replace formatted text richviewedit1 to richviewedit2 and richviewedit2 to richviewedit1
var
AStream: TMemoryStream;
BStream: TMemoryStream;
begin
AStream := TMemoryStream.Create;
BStream := TMemoryStream.Create;
RichViewEdit1.SaveRVFToStream(AStream, false);
RichViewEdit2.SaveRVFToStream(BStream, false);
AStream.Position:=0;
BStream.Position:=0;
RichViewEdit2.Clear;
RichViewEdit2.InsertRVFFromStreamEd(AStream);
RichViewEdit2.Format;
RichViewEdit1.Clear;
RichViewEdit1.InsertRVFFromStreamEd(BStream);
RichViewEdit1.Format;
AStream.Free;
BStream.Free;
richviewedit1 to richviewedit2, richviewedit2 to rich...
-
- Site Admin
- Posts: 17569
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Your code formats each TRichView twice: one time in InsertRVFFromStreamEd method (because it is an editing method), and the second time in Format.
And it may fail, because editing methods require document to be formatted before their calls, but Clear do not format document.
Solution A:
Exchange places for calls of Format and InsertRVFFromStreamEd. Format will format an empty document (after Clear), so it will be fast.
When using your code or this solution, the user can undo insertion.
Solution B:
Use LoadRVFFromStream or InsertRVFFromStream instead of InsertRVFFromStreamEd. These methods are not editing methods, so they are fast and do not format document, documents are formatted only once when you call Format.
I believe both A and B methods have a similar efficiency, about twice faster than your code.
And it may fail, because editing methods require document to be formatted before their calls, but Clear do not format document.
Solution A:
Exchange places for calls of Format and InsertRVFFromStreamEd. Format will format an empty document (after Clear), so it will be fast.
When using your code or this solution, the user can undo insertion.
Solution B:
Use LoadRVFFromStream or InsertRVFFromStream instead of InsertRVFFromStreamEd. These methods are not editing methods, so they are fast and do not format document, documents are formatted only once when you call Format.
I believe both A and B methods have a similar efficiency, about twice faster than your code.