Page 1 of 1

richviewedit1 to richviewedit2, richviewedit2 to rich...

Posted: Sun Jan 11, 2009 6:22 pm
by sr1111
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;

Posted: Mon Jan 12, 2009 10:11 am
by Sergey Tkachenko
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.