Page 1 of 1

Use TRVTableItemInfo variable as Global

Posted: Fri Oct 17, 2014 5:58 pm
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.

Posted: Sat Oct 18, 2014 5:42 am
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.

Posted: Sat Oct 18, 2014 10:14 pm
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;

Posted: Sun Oct 19, 2014 6:01 am
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.

Posted: Sun Oct 19, 2014 6:03 am
by mohsen24000
Thanks,
you need to create a copy of this table
Please how!?[/quote]

Posted: Sun Oct 19, 2014 1:16 pm
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;

Posted: Mon Oct 20, 2014 12:23 pm
by mohsen24000
When Insert or Load stream to another RV, raised exception because cells have control such as TCheckBox:
'Class TCheckBox not found'

Posted: Mon Oct 20, 2014 5:20 pm
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.