#1 2024-12-27 13:50:05

DonAlfredo
Member
Registered: 2023-10-31
Posts: 8

DocVariantToObject does not handle all fields

I am trying to use DocVariantToObject to fill an object from a variant.
Looking at the code.

if prop <> nil then
  prop^.Prop.SetValue(obj, doc.Values[p]);

This does not check the return-value of SetValue.
However, the return-value is false in case of complex fields.
So, when using this function with objects that contain classes like TCollection, then DocVariantToObject will not fill all fields.

Suggestion.

Valid := prop^.Prop.SetValue(obj,doc.Values[p]);
if (NOT Valid) then
begin
    json:=TDocVariantData(doc.Values[p]).ToJson;
    PropertyFromJson(prop,obj,pointer(json),Valid,JSONPARSER_TOLERANTOPTIONS);
end;

Offline

#2 2024-12-27 16:38:19

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

Re: DocVariantToObject does not handle all fields

Offline

#3 2024-12-27 17:34:42

DonAlfredo
Member
Registered: 2023-10-31
Posts: 8

Re: DocVariantToObject does not handle all fields

Working 100%. Thanks !!

Offline

#4 2024-12-28 10:50:04

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

Re: DocVariantToObject does not handle all fields

Thanks to YOU for your feedback and proposal!

smile

Offline

Board footer

Powered by FluxBB