You are not logged in.
Pages: 1
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
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
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
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
Your patch has been applied to http://synopse.info/fossil/info/8697c97f14
Thanks a lot for the feedback!
Offline
Pages: 1