I need to process an existing RVE document, which contains (nested) tables. A number of textstyles (which can be either in the main document or in a (nested) table cell, is assigned to some kind of code generation for a new document, so I've to parse each item. Now tables are different than RichView, so there isn't an easy way to write a recursive parser.
Is it possible to assign or copy in anyway a tablecell to a (new) RichView forth and back ?
That would make it much easier to write a recursive parser.
thanks,
Stef Mientki
treating a table cell as a RichView(Edit) ?
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Both cells contents and the main document contant can be accessed using "RVData" objects (inherited from TCustomRVFormattedData class, CRVFData unit).
Main document: TRichView(Edit).RVData.
Cells: Cell.GetRVData
RVData objects have the most of methods of TRichView.
For example, see AllUpperCase procedure in the help file, topic "Controls, Documents, Items". It uses the same methods (GetItemTextA, SetItemTextA) to change text both in the main document and in cells.
PS: Cells cannot be converted to editor. In order to perform editing operations on cell, start cell editing (table.EditCell, or cell.Edit), then use TRichViewEdit.TopLevelEditor. But this is a slow way, use it only if you really need editing operations (with undo/redo, etc.)
Main document: TRichView(Edit).RVData.
Cells: Cell.GetRVData
RVData objects have the most of methods of TRichView.
For example, see AllUpperCase procedure in the help file, topic "Controls, Documents, Items". It uses the same methods (GetItemTextA, SetItemTextA) to change text both in the main document and in cells.
PS: Cells cannot be converted to editor. In order to perform editing operations on cell, start cell editing (table.EditCell, or cell.Edit), then use TRichViewEdit.TopLevelEditor. But this is a slow way, use it only if you really need editing operations (with undo/redo, etc.)
Thanks Sergey,
The help says this about RVdata:
"This read-only property ...
While the example below ...
procedure TRichView.AddNL(const s: String; StyleNo, ParaNo: Integer);
begin
RVData.AddNL(s, StyleNo, ParaNo);
end;
I tried itas you told me, but I can't make a selection with SetSelectionBounds ...
So now I came up with this, probably a large overkill, but it works
cheers,
The help says this about RVdata:
"This read-only property ...
While the example below ...
procedure TRichView.AddNL(const s: String; StyleNo, ParaNo: Integer);
begin
RVData.AddNL(s, StyleNo, ParaNo);
end;
I tried itas you told me, but I can't make a selection with SetSelectionBounds ...
So now I came up with this, probably a large overkill, but it works
Code: Select all
(*******************************************************************************
RECURSION !!
******************************************************************************)
procedure process_RVE(var RVE_source,RVE_destination:TRichViewEdit);
var
cell_data :TcustomRVdata;
item :integer;
r,c :integer;
RVE_table :TRichViewEdit;
RVE_table_dest :TRichViewEdit;
stream :tmemorystream;
table :TRVTableItemInfo;
table_dest :TRVTableItemInfo;
table_item :integer;
temp_color :tcolor;
begin
for item:=0 to RVE_source.ItemCount-1 do
begin
case RVE_source.GetItemStyle(item) of
11:begin //scripting
process_item(RVE_source.GetItemTextA(item),RVE_destination);
end;
rvstable:
begin
//copy complete table first
with RVE_source do SetSelectionBounds(item,GetOffsBeforeItem(item),
item,GetOffsAfterItem(item));
Stream:=TMemoryStream.Create;
RVE_source.SaveRVFToStream(Stream, True);
Stream.Position := 0;
RVE_destination.AppendRVFfromStream(Stream,0);
Stream.Free;
//process all individual cells of the table
table:=TRVTableItemInfo(RVE_source.GetItem(item));
table_dest:=TRVTableItemInfo(RVE_destination.GetItem(RVE_destination.ItemCount-1));
for r:=0 to table.rows.Count-1 do
for c:=0 to table.rows[r].Count-1 do
if table.cells[r,c]<>nil then
begin
// reset the default textstyle
textstyle:=0;
try
// create 2 RichViewEdits
RVE_table:=TRichViewEdit.create(self);
RVE_table_dest:=TRichViewEdit.create(self);
RVE_table.Parent:=self;
RVE_table_dest.Parent:=self;
RVE_table.Visible:=false;
RVE_table_dest.Visible:=false;
RVE_table.Style:=RVE_source.Style;
RVE_table_dest.Style:=RVE_source.Style;
RVE_table.Options:=RVE_source.Options;
RVE_table_dest.Options:=RVE_source.Options;
// Copy source table cell to source RVE
Stream:=TMemoryStream.Create;
table.cells[r,c].SaveRVFToStream(
stream,false,clred,table.cells[r,c].getbackground,nil);
stream.Position:=0;
RVE_table.LoadRVFfromStream(stream);
RVE_table.Format;
stream.Free;
// RECURSION, process this dummy RVE with information of 1 cell
process_RVE(RVE_table,RVE_table_dest);
// Copy the resulting RVE to the destination cell
Stream:=TMemoryStream.Create;
RVE_table_dest.SaveRVFToStream(stream,false);
stream.Position:=0;
table_dest.Cells[r,c].LoadRVFFromStream(
stream,temp_color,table.cells[r,c].getbackground,nil);
table_dest.Cells[r,c].Format(true);
finally
stream.free;
RVE_table.Free;
RVE_table_dest.Free;
end;
end;
//reset the default textstyle
textstyle:=0;
end;
else //normal item
try
with RVE_source do SetSelectionBounds(item,GetOffsBeforeItem(item),
item,GetOffsAfterItem(item));
//remember the last textstyle,
// zodat deze toegepast kan worden op de content gegenereerd door het script
textstyle:=RVE_source.CurItemStyle;
//fetch the item into a stream
Stream:=TMemoryStream.Create;
RVE_source.SaveRVFToStream(Stream, True);
//paste the normal part in the destination
Stream.Position := 0;
RVE_destination.AppendRVFfromStream(Stream,0);
Stream.Free;
except
end;
end;
end;
end;
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
First, initialize cell editing, then make selection
Code: Select all
RVData := table.Cells[r,c]; // or RichViewEdit1.RVData
RVData := TCustomRVFormattedData(RVData).Edit;
RVData.SetSelectionBounds(...)