[Example] Converting table to text
Posted: Sat Jan 28, 2006 10:44 pm
This example "removes" the table at the caret position without removing its content:
The same for C++Builder:
Code: Select all
procedure ConvertTableToText(RichViewEdit: TCustomRichViewEdit);
var table: TRVTableItemInfo;
rv: TRichView;
rve: TCustomRichViewEdit;
Stream: TMemoryStream;
ItemNo,r,c: Integer;
begin
if not RichViewEdit.GetCurrentItemEx(TRVTableItemInfo, rve,
TCustomRVItemInfo(table)) then
exit;
rv := TRichView.Create(nil);
try
rv.Visible := False;
rv.Parent := RichViewEdit.Parent;
rv.Style := RichViewEdit.Style;
rv.RVFTextStylesReadMode := rvf_sIgnore;
rv.RVFParaStylesReadMode := rvf_sIgnore;
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
Stream := TMemoryStream.Create;
try
table.Cells[r,c].GetRVData.SaveRVFToStream(Stream, False, clNone, nil, nil);
Stream.Position := 0;
rv.InsertRVFFromStream(Stream, rv.ItemCount)
finally
Stream.Free;
end;
end;
ItemNo := table.GetMyItemNo;
Stream := TMemoryStream.Create;
try
rv.SaveRVFToStream(Stream, False);
Stream.Position := 0;
rve.SetSelectionBounds(ItemNo, 0, ItemNo, 1);
rve.InsertRVFFromStreamEd(Stream);
finally
Stream.Free;
end;
finally
rv.Free;
end;
end;
Code: Select all
void ConvertTableToText(TCustomRichViewEdit* RichViewEdit)
{
TCustomRVItemInfo *item;
TCustomRichViewEdit *rve;
if (! RichViewEdit->GetCurrentItemEx(__classid(TRVTableItemInfo), rve,
item))
return;
TRVTableItemInfo*table = (TRVTableItemInfo*)item;
TRichView* rv = new TRichView((TComponent*)NULL);
rv->Visible = false;
rv->Parent = RichViewEdit->Parent;
rv->Style = RichViewEdit->Style;
rv->RVFTextStylesReadMode = rvf_sIgnore;
rv->RVFParaStylesReadMode = rvf_sIgnore;
for (int r=0; r<table->Rows->Count; r++)
for (int c=0; c<table->Rows->Items[r]->Count; c++)
if (table->Cells[r][c])
{
TMemoryStream*Stream = new TMemoryStream;
table->Cells[r][c]->GetRVData()->SaveRVFToStream(Stream, false,
clNone, NULL, NULL);
Stream->Position = 0;
rv->InsertRVFFromStream(Stream, rv->ItemCount);
delete Stream;
}
int ItemNo = table->GetMyItemNo();
TMemoryStream*Stream = new TMemoryStream;
rv->SaveRVFToStream(Stream, false);
Stream->Position = 0;
rve->SetSelectionBounds(ItemNo, 0, ItemNo, 1);
rve->InsertRVFFromStreamEd(Stream);
delete Stream;
delete rv;
}