You are not logged in.
Pages: 1
CreateCopy copies DocVariant fields by reference, because GetVariantProp called with byref=true, and SetVariantProp calls VarCopyDeep, but VarCopyDeep cannot find custom variant in FindCustomVariantType with type varVariantByRef, and call oleaut32.VariantCopy.
Next, when original object destroyed, reference becomes invalid, and bad things happens.
I my case, TJsonWriter.WriteObject fails when I pass ORM object with DocVariant field, that was previously copied via CreateCopy, and original object was destroyed.
Let's say I have object like this:
TOrmA = class(TOrm)
FOpts: Variant;
published
Opts: Variant read FOpts write FOpts;
end;
Then I load object from DB or create a new one, and call CreateCopy:
a := TOrmA.Create;
a.Opts := _Obj([]);
b := a.CreateCopy;
a.Free;
Next call to TJsonWriter.WriteObject fails with EJsonException with message 'TJsonWriter.AddVariant VType=<random number>'.
Offline
Offline
Yes, It helps.
But I think the root case is in the TRttiProp.SetVariantProp - it does not handle varVariantByRef.
But varByRef used in many parts of the core units.
For example, TOrm.SetFieldVariant may also be affected:
v := _Json('{arr:[1,2]}');
a.SetFieldVariant('Opts', v.arr); // v.arr will be returned by reference
Offline
Isn't it fixed?
I check CreateCopy and SetFieldVariant. Now it works OK.
Thanks to you and commit https://github.com/synopse/mORMot2/comm … e371698401 !
Offline
Pages: 1