Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Deserialization of complex TCollectionItem descendant
Wed, Oct 31 2018 7:36 AMPermanent Link

ooptimum

In my app I need to take some tree-like structure from a server. I don't want use datasets for the sake of code clearness and productivity, since instead of making multiple requests via datasets and handling received data thereafter, I can pass the whole tree as a serialized TCollection object, which then can be used directly. However, I was faced with the fact that although the entire tree is serialized completely, only the top level is preserved during deserialization. Is this some kind of misunderstanding by me or I found a bug, which I have to report? An example is attached.



Attachments: deserialization.zip
Mon, Nov 12 2018 2:06 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Sorry for the delay in responding.

<< In my app I need to take some tree-like structure from a server. I don't want use datasets for the sake of code clearness and productivity, since instead of making multiple requests via datasets and handling received data thereafter, I can pass the whole tree as a serialized TCollection object, which then can be used directly. However, I was faced with the fact that although the entire tree is serialized completely, only the top level is preserved during deserialization. Is this some kind of misunderstanding by me or I found a bug, which I have to report? An example is attached. >>

The issue is that you aren't creating the collection for each key item as part of the creation of the key item.  Therefore, when the persistence layer tries to load the collection, it can't because the collection instance is nil (EWB will *not* automatically create instances of properties for you at runtime during loading, it will simply just load them if they are already instantiated).

The solution is to just move the sub-tree collection creation into the key items.

Tim Young
Elevate Software
www.elevatesoft.com
Wed, Nov 14 2018 7:22 AMPermanent Link

ooptimum

<< The solution is to just move the sub-tree collection creation into the key items.>>

Thank you. This constructor did the magic (maybe it will be helpful to someone else):

constructor TKeyValueItem.Create(ACollection: TCollection);
begin
 inherited Create(ACollection);
 Subtree := TKeyValueCollection.Create;
end;
Image