Use TRVTableItemInfo variable as Global

General TRichView support forum. Please post your questions here
Post Reply
mohsen24000
Posts: 75
Joined: Fri Jan 06, 2012 8:13 pm

Use TRVTableItemInfo variable as Global

Post by mohsen24000 »

Hi dear Sergey,
I want to save tables in global variable to use them any time after creation.
How do that!?
my tables contains controls such as TCheckBoxes and TGraphics in cells.
Thanks a lot.
Sergey Tkachenko
Site Admin
Posts: 17565
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

If you insert this table yourself in code, you can simply store a reference to it in a global variable.
You can use TRichView.OnItemAction event to detect when this table is deleted, and clear this reference.
mohsen24000
Posts: 75
Joined: Fri Jan 06, 2012 8:13 pm

Post by mohsen24000 »

It's impossible save table in global variable absolutely.
when define a global variable as TRVTableItemInfo and create it:

Code: Select all

table : TRVTableItemInfo;

implementation

procedure CreateTable(table : TRVTableItemInfo);
begin
table := TRVTableItemInfo.CreateEx(100,4, RVe.RVData);
...
RVe.AddItem('',table);
RVe.format;
end;

procedure A;
begin
RVe2.AddItem('',table);
RVe2.format;
end;
Sergey Tkachenko
Site Admin
Posts: 17565
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

You cannot add the same item in two trichviews.
For the second trichview, you need to create a copy of this table.
mohsen24000
Posts: 75
Joined: Fri Jan 06, 2012 8:13 pm

Post by mohsen24000 »

Thanks,
you need to create a copy of this table
Please how!?[/quote]
Sergey Tkachenko
Site Admin
Posts: 17565
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

If the both tables are inserted in TRichView linked to the same RVStyle, you can use oldtable.SaveToStream(MemoryStream) and newtable.LoadFromStream(MemoryStream) methods.

Otherwise I suggest to copy it by selecting:

Code: Select all

Stream := TMemoryStream.Create;
RV1.SetSelectionBounds(oldtable.GetMyItemNo, 0, oldtable.GetMyItemNo, 1);
RV1.SaveRVFToStream(Stream, True); // saving selected table to a stream

Stream.Position := 0;
RV2.InsertRVFFromStream(Stream, RV2.ItemCount); // adding the stream content to the end of RV2
newtable := RV2.GetItem(RV2.ItemCount-1) as TRVTableItemInfo;
RV2.Format;
Stream.Free;
mohsen24000
Posts: 75
Joined: Fri Jan 06, 2012 8:13 pm

Post by mohsen24000 »

When Insert or Load stream to another RV, raised exception because cells have control such as TCheckBox:
'Class TCheckBox not found'
Sergey Tkachenko
Site Admin
Posts: 17565
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Call RegisterClasses([TCheckBox]) one time before the first loading from RVF.
All component classes that you plan to use in documents must be registered.
Post Reply