#1 2014-10-06 12:16:25

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 506

TDocVariant Serious Problem with Add(...

Hi AB atm we encounter a serious(german: merkwürdig) Problem using TDocVariant

var
  doc : variant;
begin
  TDocVariant.New(doc);
  doc.Fehler := _Obj([]);
  doc.Fehler.Add('testfehler', true);
  assert(doc.fehler.testfehler = true, 'Fehler mit TDocVariant');
end;

On my developer Computer it works. Now we startet the programm in another computer and the assertion fails.

the Value of doc.fehler.testfehler is false

Very serious is that i get this error also sometimes in my debugger. But i didn't find the reason for this.

May you can help if you tell me how to debug it or where i have to set a breakpoint to inspect code.

Best Regards


Rad Studio 12.1 Santorini

Offline

#2 2014-10-06 13:01:01

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 506

Re: TDocVariant Serious Problem with Add(...

Solved the Problem with a cast:

DocVariantData(doc.fehler).AddValue('testfehler', true);

I found something about pseudo methods in syncommons.pas - But it seem's not to work in release mode on XE7 ?!


Rad Studio 12.1 Santorini

Offline

#3 2014-10-06 15:47:26

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

Re: TDocVariant Serious Problem with Add(...

DocVariantData or DocVariantDataSafe will always be faster than late binding.
Of course,  the following sounds safer and better:

 doc.Fehler := _Obj(['testfehler',true]);

Or even

 doc.Fehler := _Obj([]);
  doc.Fehler.testfehler := true;

But there was some random issue with parameters when using late-binding for Unicode Version of Delphi.
Even Delphi 2007 is failing passing the value... and doc.Fehler.Add('testfehler', '3') will just trigger an OutOfMemory error!

The pseudo-methods are indeed pretty unstable...
I'm afraid this is not an issue with SynCommons, but with the Delphi RTL itself...

Offline

#4 2014-10-07 13:55:55

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 506

Re: TDocVariant Serious Problem with Add(...

Hi AB ty for your response.

we'll use DocVariantData now to Add Values. Cause we have to Add multiple Values to doc.fehler we have to call the AddValue direkt.
I havent't digged as deep as you in the RTL but would it be more Safe to remove the Pseudo - Functions ?


Rad Studio 12.1 Santorini

Offline

#5 2015-09-02 03:32:19

warleyalex
Member
From: Sete Lagoas-MG, Brasil
Registered: 2013-01-20
Posts: 250

Re: TDocVariant Serious Problem with Add(...

Something that I couldn't understand:

var
  LDocVariant: variant;

begin
  LDocVariant := _JsonFast('{ "Person": { "First": { "name" : "Alex" } } }');
  LDocVariant.Person.Next := _ObjFast(['age', 31]);  // this does not work for me

expected output:
{"Person":{"First":{"name":"Alex"},"Next":{"age":31}}}
--------------------------------------------------------------------------------

LDocVariant := _Json('{"name":?,"year":?}',[],['warleyalex',1982]);  //this does not work - Ordinal type required

expected output:
{"name":"warleyalex","year":1982}

Offline

#6 2015-09-02 12:26:21

warleyalex
Member
From: Sete Lagoas-MG, Brasil
Registered: 2013-01-20
Posts: 250

Re: TDocVariant Serious Problem with Add(...

a) to add a JSON object content {"age":31} into {"Person":{"First":{"name":"Alex"}}} is works fine if you assign LDocVariant.Person.Next := LDocVariant1;

b) to produce valid JSON content from a given set of values identified by ? is better use _JsonFmt.

Offline

Board footer

Powered by FluxBB