#1 2021-09-30 22:24:00

jairgza
Member
Registered: 2015-01-15
Posts: 10

DocVar GetValueByPath raise EDocVariant property not found

Hi

According to docs GetValueByPath will return Unassigned if the path does not match with the docvar content, so it seems an easy way to read optional nodes

But this code raises "Exception class EDocVariant with message '[Imps] property not found'. "

v := _Obj([ 'Config', _Obj([]) ]);

m := _Safe(v).GetValueByPath('Config.Imps');

if VarIsEmptyOrNull(m) then
    ShowMessage('error');

I try this code too:

v := _Obj([ 'Config', _Obj([]) ]);

if not _Safe(v).GetValueByPath('Config.Imps', m) then
    ShowMessage('error');

I can use [dvoReturnNullForUnknownProperty] option but I prefer not, and be more strict and use late binding for required properties (expecting exceptions if not exist) and try read/validate optional nodes with GetValueByPath

Is it the correct behavior ?

thanks

Offline

#2 2021-10-01 16:55:26

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

Re: DocVar GetValueByPath raise EDocVariant property not found

You are right.

GetValueByPath() should not raise an exception but return false.
I have just updated TDocVariant.Lookup() to reflect this behavior.

Online

#3 2021-10-01 19:23:11

macfly
Member
From: Brasil
Registered: 2016-08-20
Posts: 374

Re: DocVar GetValueByPath raise EDocVariant property not found

hi ab,

Using the same topic about tdocvariant.

From certain decimal places on a double value json is no longer recognized as valid.
Is this expected behavior?

NOTE: I know about the loss of precision, and that I can use the dvoAllowDoubleValue option. Just checking if it's expected.

v := _JSON('{"value":0.001}'); //ok
v := _JSON('{"value":0.00001}');  //not recognized as valid json

Offline

#4 2021-10-01 20:41:50

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

Re: DocVar GetValueByPath raise EDocVariant property not found

Yes, it is as expected.
Just use _JsonFastFloat() or dvoAllowDoubleValue.

Online

#5 2021-10-01 21:23:07

jairgza
Member
Registered: 2015-01-15
Posts: 10

Re: DocVar GetValueByPath raise EDocVariant property not found

ab wrote:

You are right.

GetValueByPath() should not raise an exception but return false.
I have just updated TDocVariant.Lookup() to reflect this behavior.

Thanks for your quick respond,  I see the fix in mormot2
but not in 1.18 , Im using that version,  sorry I did not mention it  roll

Offline

Board footer

Powered by FluxBB