#1 2015-02-18 14:58:44

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

CrossplatformJSON Exception Loading TSQLRecord with Reference

Hi Arnaud,

XE7/8:

i get the following Exception loading a TSQLRecord derived Class A with Reference to TSQLRecord Class B

class B : TSQLRecord
  value : RawUtf8;
...
end;

class A : TSQLRecord
  value : RawUtf8;
  FB : B;
...
end;

EJSONException mit Meldung 'JSONVariantData.Data(20<>JSONVariant)'. Prozess xyz.exe (896)

i use

var
  LA : A;
begin
  LA := A.Create(database, '*', 'value=?', ['test']);   <- Exception;

The JSON which is parsed has the right TID at the right place.
Btu Resolving this Reference

  with TVarData(JSONVariant) do
    if VType=JSONVariantType.VarType then
      result := @JSONVariant else
    if VType=varByRef or varVariant then
      result := JSONVariantData(PVariant(VPointer)^) else
    raise EJSONException.CreateFmt('JSONVariantData.Data(%d<>JSONVariant)',[VType]);

raises the Exception. VType is 20  and JSONVariantType.VarType = 274

Last edited by itSDS (2015-02-18 15:01:50)


Rad Studio 12.1 Santorini

Offline

#2 2015-02-18 15:10:00

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

Re: CrossplatformJSON Exception Loading TSQLRecord with Reference

As a workaround i modified JSONVariantData

function JSONVariantData(const JSONVariant: variant): PJSONVariantData;
begin
  with TVarData(JSONVariant) do
    if (VType=JSONVariantType.VarType) or (VType=20) then
      result := @JSONVariant else
    if VType=varByRef or varVariant then
      result := JSONVariantData(PVariant(VPointer)^) else
    raise EJSONException.CreateFmt('JSONVariantData.Data(%d<>JSONVariant)',[VType]);
end;

this worked smile - But i think there is another way ...


Rad Studio 12.1 Santorini

Offline

#3 2015-02-18 15:11:48

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

Re: CrossplatformJSON Exception Loading TSQLRecord with Reference

Could you please create a ticket?
With a link to this forum thread.

Thanks!

Offline

#4 2015-02-18 15:57:47

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

Re: CrossplatformJSON Exception Loading TSQLRecord with Reference

After some Debugging: my workaround does not fix the Problem. Only the Exception is gone. But the Reference is not filled with the TID, it is nil

Ticket http://synopse.info/fossil/tktview/0ebc … c73b904712 created

Last edited by itSDS (2015-02-18 15:59:55)


Rad Studio 12.1 Santorini

Offline

#5 2015-02-21 11:06:14

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

Re: CrossplatformJSON Exception Loading TSQLRecord with Reference

Push - Hi Arnaud, i need this functionality. I can not load Data with CrossPlatform Client.

tyvm


Rad Studio 12.1 Santorini

Offline

#6 2015-02-27 12:18:30

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

Re: CrossplatformJSON Exception Loading TSQLRecord with Reference

Hi Arnaud i can not load TSQLRecord with Reference to other TSQLRecord as Pointer.
I think the main Problem is ARC.

I tried a little list with AddObject('entry1', TObject(1));  This doesn't work on iOS / Android either. Cause ARC tries de decrease RefCount of the 1 smile

In TSQLRecord there will be the same Problem...
I'm thinking about removing the TSQLRecord Reference and replace it with TID for iOS / Android. Than it should work again.


Rad Studio 12.1 Santorini

Offline

#7 2015-02-27 12:39:59

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

Re: CrossplatformJSON Exception Loading TSQLRecord with Reference

I was not thinking about ARC, but you are right: it should be a true pointer, not an integer transtyped as fake pointer.

Yes, using TID should do the trick, at all levels: serialization (plain integer value), and ARC behavior.

Offline

#8 2015-02-27 13:09:07

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

Re: CrossplatformJSON Exception Loading TSQLRecord with Reference

is it possible to change the record reference in CrossPlatformwrapper to TID ? I don't want to change my TSQLRecord cause on other Platforms i wan't to use the Pointer.
it could be surounded with
if defined(AUTOREFCOUNT) ...

something like :

{$if defined(AUTOREFCOUNT)}TID{$else}TSQLDFLRecord{$endif}

Last edited by itSDS (2015-02-27 13:18:25)


Rad Studio 12.1 Santorini

Offline

#9 2015-02-27 13:18:19

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

Re: CrossplatformJSON Exception Loading TSQLRecord with Reference

Please try http://synopse.info/fossil/info/af10bf7303

No need to check for the compiler target: I just use TID for crossplatform clients, with a reference as comment to the original type declaration.
It is therefore up to the client code to use this TID as expected.

Offline

#10 2015-02-27 14:23:57

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

Re: CrossplatformJSON Exception Loading TSQLRecord with Reference

ty - now i can work with it. (But the BUG in the ticket is not fixed yet) it's just a workaround smile


Rad Studio 12.1 Santorini

Offline

#11 2015-02-27 14:45:33

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

Re: CrossplatformJSON Exception Loading TSQLRecord with Reference

I'm afraid that due to ARC expectations, we won't be able to do anything better.

Is not having the TID and work with ID not enough?

Offline

#12 2015-02-27 15:31:42

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

Re: CrossplatformJSON Exception Loading TSQLRecord with Reference

In fact it is enough.
For the most cases i write interface functions.


Rad Studio 12.1 Santorini

Offline

#13 2015-02-27 17:23:57

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

Re: CrossplatformJSON Exception Loading TSQLRecord with Reference

Yes, proper DTO over regular SOA interfaces sounds a cleaner approach to me.

Offline

Board footer

Powered by FluxBB