Skip to content

Commit

Permalink
new TDocVariantData.InitArrayFromObjectValues() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud Bouchez committed Oct 19, 2022
1 parent 7fff51d commit 38e7a0b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
23 changes: 20 additions & 3 deletions src/core/mormot.core.variants.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,10 @@ TDocVariantData = record
// - if you call Init*() methods in a row, ensure you call Clear in-between
procedure InitArrayFromVariants(const aItems: TVariantDynArray;
aOptions: TDocVariantOptions = [];
aItemsCopiedByReference: boolean = true);
aItemsCopiedByReference: boolean = true; aCount: integer = -1);
/// initialize a variant array instance from an object Values[]
procedure InitArrayFromObjectValues(const aObject: variant;
aOptions: TDocVariantOptions = []; aItemsCopiedByReference: boolean = true);
/// initialize a variant instance to store some RawUtf8 array content
procedure InitArrayFrom(const aItems: TRawUtf8DynArray;
aOptions: TDocVariantOptions); overload;
Expand Down Expand Up @@ -5000,20 +5003,34 @@ procedure TDocVariantData.InitArray(const aItems: array of const;
end;

procedure TDocVariantData.InitArrayFromVariants(const aItems: TVariantDynArray;
aOptions: TDocVariantOptions; aItemsCopiedByReference: boolean);
aOptions: TDocVariantOptions; aItemsCopiedByReference: boolean; aCount: integer);
begin
if aItems = nil then
TRttiVarData(self).VType := varNull
else
begin
Init(aOptions, dvArray);
VCount := length(aItems);
if aCount < 0 then
VCount := length(aItems)
else
VCount := aCount;
VValue := aItems; // fast by-reference copy of VValue[]
if not aItemsCopiedByReference then
InitCopy(variant(self), aOptions);
end;
end;

procedure TDocVariantData.InitArrayFromObjectValues(const aObject: variant;
aOptions: TDocVariantOptions; aItemsCopiedByReference: boolean);
var
dv: PDocVariantData;
begin
if _SafeObject(aObject, dv) then
InitArrayFromVariants(dv^.Values, aOptions, aItemsCopiedByReference, dv^.Count)
else
TRttiVarData(self).VType := varNull;
end;

procedure TDocVariantData.InitArrayFromObjArray(const ObjArray;
aOptions: TDocVariantOptions; aWriterOptions: TTextWriterWriteObjectOptions);
var
Expand Down
2 changes: 1 addition & 1 deletion src/mormot.commit.inc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
'2.0.4219'
'2.0.4220'

0 comments on commit 38e7a0b

Please sign in to comment.