You are not logged in.
Pages: 1
Delphi 11.1, mORMot 3294
Following test function:
var
item: Variant;
list: Variant;
begin
TDocVariant.New(item, [dvoIsObject]);
TDocVariantData(list).Init([dvoIsArray]);
for var idx: Integer := 0 to 100 do
begin
item.id := idx;
item.source := StringToUtf8('source' + idx.ToString);
item.target := StringToUtf8('target' + idx.ToString);
TDocVariantData(list).AddValue(StringToUtf8('edge' + idx.ToString), item, True);
end;
FileFromString(TDocVariantData(TDocVariantData(list).ReduceAsArray('source')).ToCsv, '_testData.csv');
In the following source code IsArray prevents any further execution.
procedure TDocVariantData.ReduceAsArray(const aPropName: RawUtf8;
var result: TDocVariantData; const OnReduce: TOnReducePerItem);
var
ndx: PtrInt;
item: PDocVariantData;
v: PVariant;
begin
TVarData(result) := DV_FAST[dvArray];
if (VCount <> 0) and
(aPropName <> '') and
IsArray then
If you rewrite the selection as follows, you can see the problem.
if VCount = 0 then Exit;
if aPropName = '' then Exit;
if not IsArray then Exit;
If IsArray is commented out, you get the desired result.
With best regards
Thomas
Offline
Instead of
for var idx: Integer := 0 to 100 do
you can use
for var idx := 0 to 100 do
Offline
ReduceAsArray() works on an array of objects, not an object.
Your AddValue() call transforms list into an object.
Now that I've stepped through the source code one by one, I've noticed it. With the following it works as it should:
TDocVariantData(list).AddItem(item);
Thanks for the hint.
Instead of
for var idx: Integer := 0 to 100 do
you can use
for var idx := 0 to 100 do
I know that, but this magic feels a little weird to me. I am too old for that.
With best regards
Thomas
Offline
Pages: 1