You are not logged in.
A question I have is, what happens when you use some TPersistent in TSQLRecord, and you assign and object for an inherited class to it.
TMyPersistent = class(TPersistent)
private
FName: String;
published
Name: string read Fname write Fname;
end;
TMyDerived = class(TMyPersistent)
private
FAddress: string;
published
Address: String read FAddress write FAddress;
end;
TMyRecord = class(TSQLRecord)
private
FPers: TMyPersistent;
published
Pers: TMyPersistent read FPers write FPers;
end;
What happens when i assign a instance of TMyDerived to TMyRecord.Pers and write that to a database? Will the Address property be written to?
What happens when i read TMyRecord back from the database? Will it create an TMyPersistent object or a TMyDerived object?
Offline
I suspect you need the exact same class (or at least published properties) to be used.
There is no "class type" in the JSON serialization, so at read, it will create a TMyPersistent instance, even if at writing stage, it was a TMyDerived instance.
Offline
Mmm .. too bad :-(
That will force us to go back to the Delphi streaming system
Offline
It may be linked to the http://synopse.info/fossil/tktview?name=cacaaf8f33 implementation.
That is, store the class name within the JSON stream.
But you will need the class type to be serialized.
Not truly JSON content...
DataSnap for instance uses some custom format with some additional members for this, but this breaks pretty much the JSON content, and makes it difficult to consume it from AJAX clients, unless you write your own wrapper code.
Custom JSON serialization of classes can be used to by-pass this issue.
That is, you can register you own TMyPersistent serializer.
But the problem may comes from the fact that the framework needs to be extended to create a TMyDerived instance instead of TMyPersistent, depending on the JSON content. This is not possible by now.
I suspect all this may be a bit confusing.
Worth another feature request, since serializing the class name optionally may be the first step to cacaaf8f33 feature.
Offline