Rtti data manipulation and consistency in Delphi 2010
- by Coco
Has anyone an idea, how I can make TValue using a reference to the original data? In my serialization project, I use (as suggested in XML-Serialization) a generic serializer which stores TValues in an internal tree-structure (similar to the MemberMap in the example).
This member-tree should also be used to create a dynamic setup form and manipulate the data.
My idea was to define a property for the Data:
TDataModel <T> = class
{...}
private
FData : TValue;
function GetData : T;
procedure SetData (Value : T);
public
property Data : T read GetData write SetData;
end;
The implementation of the GetData, SetData Methods:
procedure TDataModel <T>.SetData (Value : T);
begin
FData := TValue.From <T> (Value);
end;
procedure TDataModel <T>.GetData : T;
begin
Result := FData.AsType <T>;
end;
Unfortunately, the TValue.From method always makes a copy of the original data. So whenever the application makes changes to the data, the DataModel is not updated and vice versa if I change my DataModel in a dynamic form, the original data is not affected.
Sure I could always use the Data property before and after changing anything, but as I use lot of Rtti inside my DataModel, I do not realy want to do this anytime.
Perhaps someone has a better suggestion?