#1 2015-04-10 17:36:29

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

Error in CrossplatformClient Generation

Hi Arnaud,

today i found the following error:

If you define somthing like this

  RRec1 = record
    TextValue: String;
  end;

  RRec2 = record
    TextValue: String;
    ArrayOfRRec1: array of RRec1;
  end;

  RRec3 = record
    TextValue: String;
    ArrayOfRec2: array of RRec2;
  end;

The generated CrossPlatformClient - Code has the following error:

function Variant2RRec1(_variant: variant): RRec1;
function RRec12Variant(const _record: RRec1): variant;
function Variant2RRec2(_variant: variant): RRec2;
function RRec22Variant(const _record: RRec2): variant;
function Variant2RRec3(_variant: variant): RRec3;
function RRec32Variant(const _record: RRec3): variant;

.....


function Variant2RRec1(_variant: variant): RRec1;
var _a: integer;
    _arr: PJSONVariantData;
begin
  result.TextValue := _variant.TextValue;
end;

function RRec12Variant(const _record: RRec1): variant;
var i: integer;
    res: TJSONVariantData;
begin
  res.Init;
  res.SetPath('TextValue',_record.TextValue);
  result := variant(res);
end;

function Variant2RRec2(_variant: variant): RRec2;
var _a: integer;
    _arr: PJSONVariantData;
begin
  result.TextValue := _variant.TextValue;
  _arr := JSONVariantDataSafe(_variant.ArrayOfRRec1,jvArray);
  SetLength(result.ArrayOfRRec1,_arr^.Count);
  for _a := 0 to high(result.ArrayOfRRec1) do
    result.ArrayOfRRec1[_a] := _arr^.Values[_a]; // Error
end;

function RRec22Variant(const _record: RRec2): variant;
var i: integer;
    res: TJSONVariantData;
begin
  res.Init;
  res.SetPath('TextValue',_record.TextValue);
  with res.EnsureData('ArrayOfRRec1')^ do
    for i := 0 to high(_record.ArrayOfRRec1) do
      AddValue(_record.ArrayOfRRec1[i]); // Error
  result := variant(res);
end;

function Variant2RRec3(_variant: variant): RRec3;
var _a: integer;
    _arr: PJSONVariantData;
begin
  result.TextValue := _variant.TextValue;
  _arr := JSONVariantDataSafe(_variant.ArrayOfRec2,jvArray);
  SetLength(result.ArrayOfRec2,_arr^.Count);
  for _a := 0 to high(result.ArrayOfRec2) do
    result.ArrayOfRec2[_a] := _arr^.Values[_a]; // Error
end;

function RRec32Variant(const _record: RRec3): variant;
var i: integer;
    res: TJSONVariantData;
begin
  res.Init;
  res.SetPath('TextValue',_record.TextValue);
  with res.EnsureData('ArrayOfRec2')^ do
    for i := 0 to high(_record.ArrayOfRec2) do
      AddValue(_record.ArrayOfRec2[i]); // Error
  result := variant(res);
end;

I marked 4 Lines with Error

in the array - loop you have to use the Rec2Variant and Variant2Rec - Functions

function RRec12Variant(const _record: RRec1): variant;
var i: integer;
    res: TJSONVariantData;
begin
  res.Init;
  res.SetPath('TextValue',_record.TextValue);
  result := variant(res);
end;

function Variant2RRec2(_variant: variant): RRec2;
var _a: integer;
    _arr: PJSONVariantData;
begin
  result.TextValue := _variant.TextValue;
  _arr := JSONVariantDataSafe(_variant.ArrayOfRRec1,jvArray);
  SetLength(result.ArrayOfRRec1,_arr^.Count);
  for _a := 0 to high(result.ArrayOfRRec1) do
    result.ArrayOfRRec1[_a] := Variant2RRec1(_arr^.Values[_a]);
end;

function RRec22Variant(const _record: RRec2): variant;
var i: integer;
    res: TJSONVariantData;
begin
  res.Init;
  res.SetPath('TextValue',_record.TextValue);
  with res.EnsureData('ArrayOfRRec1')^ do
    for i := 0 to high(_record.ArrayOfRRec1) do
      AddValue(RRec1ToVariant(_record.ArrayOfRRec1[i]));
  result := variant(res);
end;

function Variant2RRec3(_variant: variant): RRec3;
var _a: integer;
    _arr: PJSONVariantData;
begin
  result.TextValue := _variant.TextValue;
  _arr := JSONVariantDataSafe(_variant.ArrayOfRec2,jvArray);
  SetLength(result.ArrayOfRec2,_arr^.Count);
  for _a := 0 to high(result.ArrayOfRec2) do
    result.ArrayOfRec2[_a] := VariantToRRec2(_arr^.Values[_a]);
end;

function RRec32Variant(const _record: RRec3): variant;
var i: integer;
    res: TJSONVariantData;
begin
  res.Init;
  res.SetPath('TextValue',_record.TextValue);
  with res.EnsureData('ArrayOfRec2')^ do
    for i := 0 to high(_record.ArrayOfRec2) do
      AddValue(RRec2ToVariant(_record.ArrayOfRec2[i]));
  result := variant(res);
end;

can you please integrate it in the Mustache - Wrapper?


Rad Studio 12.1 Santorini

Offline

#2 2015-04-10 19:51:41

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

Re: Error in CrossplatformClient Generation

Please try to define a type for the dynamic array:

 RRec1 = record
    TextValue: String;
  end;
  RRec1DynArray = array of RRec1;
  RRec2 = record
    TextValue: String;
    ArrayOfRRec1: RRec1DynArray ;
  end;
  RRec2DynArray = array of RRec2;
  RRec3 = record
    TextValue: String;
    ArrayOfRec2: RRec2DynArray;
  end;

Offline

#3 2015-04-11 08:44:40

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

Re: Error in CrossplatformClient Generation

I testet it with the same result. RRec1/2DynArray is convertet to array or RRec1/2 and declaration of RRec1/2DynArray is missing.


Rad Studio 12.1 Santorini

Offline

#4 2015-04-16 22:26:02

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

Re: Error in CrossplatformClient Generation

Hi Arnaud, can you fix this please - atm i have to change nearly 100 Lines of code after Wrapper generation...


Rad Studio 12.1 Santorini

Offline

#5 2015-04-17 14:01:22

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

Re: Error in CrossplatformClient Generation

Your patch has been applied to http://synopse.info/fossil/info/8697c97f14

Thanks a lot for the feedback!

Offline

Board footer

Powered by FluxBB