Inserting TRichViewEdit content into several table cells

General TRichView support forum. Please post your questions here
Post Reply
GreatMilenko
Posts: 3
Joined: Tue Aug 28, 2007 2:34 pm

Inserting TRichViewEdit content into several table cells

Post by GreatMilenko »

Hello!

I have an application where i want to store the content of a TRichViewEdit into several table cells, the content is saved to a memorystream using SaveRVFToStream() and later on retrieved from the memory stream and inserted into a new TRichViewEdit that has a large table where every cell corresponds to the content of the first TRichViewEdit (it is loaded into the table using table.Cells[x,x].LoadRVFFromStream().
The reasoning behind this complicated way of doing things is that the application is a subtitle editor and every subtitle needs to be edited as though it was a standalone document, although with only one page, and finally saved out into RTF format in a single table.
However the application fails when trying to save in RTF format and i get a "List index out of bounds (xx)" in the first line of the function:
TRVFontInfoCacheFast.GetItems(Index: Integer): TRVFontInfoCacheItem;
The application looks like this:

DubEditexporter is a TRichViewEdit control

DubTextStream := TMemoryStream.Create();
DubEditexporter.Clear();
DubEditexporter.DeleteUnusedStyles(true, true, true);

table := TRVTableItemInfo.CreateEx(m_MemManager.Count + 1, 4, DubEditexporter.RVData);
table.Cells[0, 0].Clear;
table.Cells[0, 1].Clear;
table.Cells[0, 2].Clear;
table.Cells[0, 3].Clear;


// Width
table.SetCellBestWidth(100, 0, 0);
table.SetCellBestWidth(80, 0, 1);
table.SetCellBestWidth(100, 0, 2);
table.SetCellBestWidth(320, 0, 3);

table.Cells[0, 0].AddNL('Character: ', 6, 1);
table.Cells[0, 1].AddNL('Timecode: ', 6, 1);
table.Cells[0, 2].AddNL('Note: ', 6, 1);
table.Cells[0, 3].AddNL('Line: ', 6, 1);
table.BorderWidth := 0;
table.CellBorderWidth := 0;
tableColor := DubEditexporter.Color;

for t := 0 to m_MemManager.Count - 1 do begin
txt := m_MemManager.Get(t);

table.Cells[t + 1, 0].Clear;
table.Cells[t + 1, 1].Clear;
table.Cells[t + 1, 2].Clear;
table.Cells[t + 1, 3].Clear;

table.Cells[t + 1, 0].AddNL(txt.Speaker, 0, 1);
table.Cells[t + 1, 1].AddNL(TCEdit.MiliToTC(txt.InTime), 0, 1);
table.Cells[t + 1, 2].AddNL(txt.Notes, 0, 1);

txt.DubTextStream.Position := 0;
table.Cells[t + 1, 3].LoadRVFFromStream(txt.DubTextStream, tableColor, DubEditexporter.Background, nil);
table.Cells[t + 1, 3].Format(true);

end;
DubEditexporter.AddItem('ContentTable', table);
DubEditexporter.Format();
DubEditexporter.SaveRTF(sFileName, false);



Forgot to mention that i have a registered version of TRichViewEdit and its version is RichView 1.9.44.2
Last edited by GreatMilenko on Thu Aug 30, 2007 12:07 pm, edited 1 time in total.
GreatMilenko
Posts: 3
Joined: Tue Aug 28, 2007 2:34 pm

Post by GreatMilenko »

Hello?

Anybody got ideas for what might be wrong, Sergey?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Cell.LoadRVFFromStream does not support work with styles. That means, before calling it, you need to set RVFTextStylesReadMode = RVFParaStylesReadMode = rvf_sIgnore for TRichView containing this table. So this method can load only documents containing the same set of styles as TRichView containing this table.

Solutions:
1) See Demos\Delphi\Assorted\Fields\MailMerge2\. This demo loads document to the hidden TRichView (RichView2) linked to the same RVStyle as TRichView containing table (RichView1). Now styles are the same in RichView1 and RichView2, document is saved from RichView2 without styles, and can be loaded in cell of table in RichView1.

or

2) Use RTF format instead of RVF for copying.
GreatMilenko
Posts: 3
Joined: Tue Aug 28, 2007 2:34 pm

Post by GreatMilenko »

Thanks i used .rtf format for copying and that did the trick, do you know of any potential problems by doing it that way?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Some information that cannot be saved in RTF will be lost.
But if you create this table for saving in RTF, it does not matter.
Post Reply