List index out of bounds when deleting cell text

General TRichView support forum. Please post your questions here
Post Reply
mphilbrick
Posts: 27
Joined: Mon Aug 29, 2005 7:08 pm

List index out of bounds when deleting cell text

Post by mphilbrick »

Sergey,

I read the post "Inserting TRichViewEdit content into several table cells" from August 2007 and I selected option 1, which was to set the read modes to rvf_signore. I use the following code to copy selected RVF text from one control to the cell of another. It copies fine, and it looks like it should.

If I double-click to highlight the text that was entered and then delete it, I get the "list index out of bounds" error. This occurs whether or not there is other text in the cell, and whether it was entered before or after the inserted text. However, if I include other text as well as the inserted text and delete, or if I only delete part of the inserted text, there is no error.

procedure TdmRichViewMod.CopyRVToCellText(rvSource : TRichViewEdit;
rvCellDest : TRVTableCellData; SelectionOnly : boolean;
rvUpdateStyle : TRichView);
var
MS_Dest : TMemoryStream;
Dummy1 : TColor;
Dummy2, Dummy3 : Pointer;
begin
// add RVF to individual cell
Dummy1 := clNone;
Dummy2 := nil;
Dummy3 := nil;
try
MS_Dest := TMemoryStream.Create;
// write directly to TRichView object first so styles are merged ...
// cell-based RVF functions do not merge styles
rvSource.SaveRVFToStream(MS_Dest, SelectionOnly);
MS_Dest.Position := 0;
rvUpdateStyle.Clear;
rvUpdateStyle.InsertRVFFromStream(MS_Dest, 0); // inserting will merge styles;
rvUpdateStyle.Format;
MS_Dest.Clear;
rvUpdateStyle.SaveRVFToStream(MS_Dest, False);
MS_Dest.Position := 0;
rvCellDest.AppendRVFFromStream(MS_Dest, -1, Dummy1, Dummy2);
rvUpdateStyle.Clear;
finally
MS_Dest.Free;
end;
end;

rvUpdateStyle is set to the same style as the destination editor but the source editor is connected to a different style.

The destination editor is TRichViewEdit whereas rvUpdateStyle is TRichView

Note the AppendRVFFromStream parameters: I set ParaNo to -1 so that it will not create a new paragraph. If I change this to "0" I never get the error but I now have a new paragraph with potentially a different style than the cell default.

Please tell me what to modify to get this to work. One option is to delete the paragraph marker after inserting the text. I am not sure how to do that without deleting the entire paragraph that was just entered. If you do not have another solution, could you show me how to go from a) to b)?

a) how it looks now using "0" as ParaNo:

this is original-
this is inserted into the cell

b) how I want it to look by deleting the paragraph marker:

this is original-this is inserted into the cell
Sergey Tkachenko
Site Admin
Posts: 17310
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

AppendRVFFromStream may produce invalid documents when used incorrectly.
You can call NormalizeRichView (RVNormalize.pas, included in RichViewActions) after this operation but before formatting TRichView containing this cell. This procedure will fix errors in the document.
mphilbrick
Posts: 27
Joined: Mon Aug 29, 2005 7:08 pm

Post by mphilbrick »

Sergey,

Works great! Thank you.
Post Reply