Page 1 of 1

Errors when saving and loading RVF from stream

Posted: Wed Jun 06, 2007 12:50 pm
by martindholmes
Hi there,

I'm trying to implement a crude undo system for operations which cannot be undone through the normal Undo functionality (for instance, after using functions like those described here: http://www.trichview.com/forums/viewtop ... =6701#6701

Basically, what I want to do is stream out the contents of a TRichViewEdit into a memory stream, then allow it to be streamed back if necessary. However, when I try to stream the data back into the memory stream, I get multiple instances of this:

EStringListError with message "List index out of bounds (-1)"

Here's the basic code. FBackupMemStream is a TMemoryStream created and destroyed by the TMarkRichView object in its constructor and destructor. RVE is a TRichViewEdit control.

procedure TMarkRichView.StashBackupStream;
begin
FBackupMemStream.Clear;
RVE.SaveRVFToStream(FBackupMemStream, False);
end;

procedure TMarkRichView.RestoreFromBackupStream;
begin
if FBackupMemStream.Size < 1 then
Exit;
RVE.Clear;
RVE.DeleteUnusedStyles(True, True, True);
RVE.Format;
FBackupMemStream.Position := 0;
RVE.LoadRVFFromStream(FBackupMemStream);
end;

In my test code, I call these two functions one after the other:

MRV.StashBackupStream;
//Do something...
MRV.RestoreFromBackupStream;


Can anyone see what might be causing the problem here?

All help appreciated,
Martin

Posted: Fri Jun 08, 2007 7:32 pm
by Sergey Tkachenko
I'll answer when I return from vacations

Posted: Thu Jun 21, 2007 11:48 am
by martindholmes
Gentle bump for this question...

Posted: Thu Jun 21, 2007 1:24 pm
by sigbert
procedure TMarkRichView.RestoreFromBackupStream;
begin
if FBackupMemStream.Size < 1 then
Exit;
RVE.Clear;
RVE.DeleteUnusedStyles(True, True, True);
RVE.Format;
FBackupMemStream.Position := 0;
RVE.LoadRVFFromStream(FBackupMemStream);
RVE.Format;
end;

Posted: Fri Jun 22, 2007 1:31 am
by Sergey Tkachenko
I just do not have Delphi here and I can only answer questions that do not require testing.
But it looks like sigbert's suggestion is correct

Posted: Fri Jun 22, 2007 11:46 am
by martindholmes
That did it!

I keep forgetting that format call. Doh!

Cheers,
Martin