You are not logged in.
I have created a TSQLRecord class which contains a TCollection as one of its properties.In my test the Collection contains two items.
TSQLWorkbaseObject = class(TSQLWorkbaseBaseObject)
type
TValueColItem = class(TCollectionItem)
private
Fname: RawUTF8;
FAttrDef: TWBDynAttributeDef;
FValue: TLCSDataObject;
published
property Name: RawUTF8 index 50 read FName write FName;
property AttributeDef: TWBDynAttributeDef read FAttrDef write FAttrDef;
property ValueObject: TLCSDataObject read FValue write FValue;
end;
TValueCollection = class(TCollection)
private
function GetCollItem(Index: Integer): TValueColItem;
public
function Add: TValueColItem;
property ItemIndex: Integer: TValueColItem read GetCollItem; default;
end;
var
private
FImplementerClassCode: RawUTF8;
FName: RawUTF8;
FWBID: TSQLRecordID;
FValCol: TValueCollection;
public
constructor Create; override;
destructor Destroy; override;
published
property ImplementerClassCode:RawUTF8 index 8 read FImplementerClassCode write FImplementerClassCode;
property WorkbaseObjectID: TSQLRecordID read FWBID write FWBID stored false; //Unique!!
property Name: RawUTF8 index 50 read FName write FName;
property ValueList: TValueCollection read FValCol write FValCol;
end;
Writing the collection seems to go well, resulting in the following JSON value:
'[{"Name":"ValueName1","AttributeDef":{"DisplayName":"","Name":"ValueName1","WBAttributeClass":"TLCSSimpleValue"},"ValueObject":{"AsString":"Dit is een tekstje"}},
{"Name":"ValueName2","AttributeDef":{"DisplayName":"","Name":"ValueName2","WBAttributeClass":"TLCSSimpleValue"},"ValueObject":{"AsFloat":34.665}}]'
When the collection is read back by JSONToObject it only reads one of the items ...
Also registered as ticket: http://synopse.info/fossil/info/f99c86b1ac
Last edited by Bascy (2013-01-14 10:39:47)
Offline
Further investigation learns that reading of the collection end in error when the TValColItem.AttributeDef value is read from the JSON stream.
To be more precise, the following call in mORMot.pas line 25742 results in nil
PObject(P^.GetFieldAddr(Value))^
The definition of TWBDynAttributeDef:
TWBDynAttributeDef = class(TLCSDataObject, IWBDynAttributeDef) {TLCSDataObject is derived from TPersistent}
private
FDisplayName: string;
FName: string;
FWBAttributeClass: string;
protected
function GetAttribClass: string;
function GetName: string;
procedure SetAttribClass(const aValue: string);
procedure SetName(const aValue: string);
published
property DisplayName: string read FDisplayName write FDisplayName;
property Name: string read GetName write SetName;
property WBAttributeClass: string read GetAttribClass write SetAttribClass;
end;
Offline
Already created a ticket: http://synopse.info/fossil/info/f99c86b1ac
Offline
The title of the ticket is misleading.
Unless the cause is indeed the fact that there are both getter and setter methods, but no direct access to the property.
I guess this is the same as the issue described in the forum at http://synopse.info/forum/viewtopic.php?id=906
I've updated the ticket description.
Offline
Should be fixed by http://synopse.info/fossil/info/1fc6a7f0bf
- added TTypeInfo.ClassCreate() method to create a TObject instance from RTTI
- added TPropInfo.ClassFromJSON() to properly unserialize TObject properties
- fixed TInterfacedCollection.GetClass to be defined as a class function
- GetOrdProp(), SetOrdProp(), GetInt64Prop(), SetInt64Prop(), GetLongStrProp(), SetLongStrProp() code refactoring
Huge code refactoring.
Offline