You are not logged in.
Pages: 1
I think the description to class TSynAutoCreateFields is not consistent. You write: "...any class defined as a published property will be owned by this instance". And elsewhere you write: "...this overriden constructor will instantiate all its nested TPersistent/TSynPersistent/TSynAutoCreateFields published properties". But it also works with descendants of TObject:
type
TSubItem = class(TObject)
private
FSubValue: RawUtf8;
published
property SubValue: RawUtf8 read FSubValue write FSubValue;
end;
TItem = class(TSynAutoCreateFields)
private
FValue: RawUtf8;
FSubItem: TSubItem;
published
property Value: RawUtf8 read FValue write FValue;
property SubItem: TSubItem read FSubItem;
end;
var
item: TItem;
list: TObjectList;
begin
list := TObjectList.Create;
try
item := TItem.Create;
item.Value := StringToUtf8('value' + 1.ToString);
item.SubItem.SubValue := StringToUtf8('subValue' + 1.ToString);
list.Add(item);
ObjectToJsonFile(list, '_listData.json');
finally
list.Free;
end;
end;
With best regards
Thomas
Offline
You are right, it sounds confusing.
The idea was that you need to have RTTI enabled for the class instance, which is the case for TPersistent/TSynPersistent. But not for a plain TObject.
Your code TSubItem = class(TObject) will force to generate the RTTI for it, even if it inherits from plain TObject, because you defined published properties - there is in fact a warning in the compiler messages.
But there is in fact no limitation to TPersistent/TSynPersistent/TSynAutoCreateFields classes.
I have made the comments a little more explicit.
Please see https://github.com/synopse/mORMot2/commit/11283a76
Offline
Pages: 1