#1 2013-01-14 09:33:48

Bascy
Member
From: The Netherlands
Registered: 2012-06-22
Posts: 108

Reading TCollection property of TSQLRecord does not read all items

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

#2 2013-01-14 11:18:09

Bascy
Member
From: The Netherlands
Registered: 2012-06-22
Posts: 108

Re: Reading TCollection property of TSQLRecord does not read all items

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

#3 2013-01-14 16:25:44

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,550
Website

Re: Reading TCollection property of TSQLRecord does not read all items

There is no "offset" information available for the WBAttributeClass property, since both getter and setter are methods.

A ticket is needed here.

Offline

#4 2013-01-14 16:28:53

Bascy
Member
From: The Netherlands
Registered: 2012-06-22
Posts: 108

Re: Reading TCollection property of TSQLRecord does not read all items

Already created a ticket: http://synopse.info/fossil/info/f99c86b1ac

Offline

#5 2013-01-14 16:29:54

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,550
Website

Re: Reading TCollection property of TSQLRecord does not read all items

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

#6 2013-01-15 11:02:19

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,550
Website

Re: Reading TCollection property of TSQLRecord does not read all items

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

Board footer

Powered by FluxBB