FireDAC.Phys.MongoDBWrapper.TMongoDocument.Iterator
Delphi
function Iterator: TJSONIterator;
C++
System::Json::Builders::TJSONIterator* __fastcall Iterator();
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
function | public | FireDAC.Phys.MongoDBWrapper.pas FireDAC.Phys.MongoDBWrapper.hpp |
FireDAC.Phys.MongoDBWrapper | TMongoDocument |
Description
Creates new instance and returns a reference to a JSON iterator.
NOTE: The caller of this method should free the iterator object after its using.
Examples
Consider the following scenario:
- You added a document to a MongoDB dataset using the sample code from BeginObject
- This document contains the Label1 field, which holds an embedded document with three key-value pairs: "Top": 30, "Left": 30, and "Caption": "Enter value:".
- You dropped a label (referred to as Label2 variable of the TLabel type in our example) to your application form.
The following code snippet illustrates how to use the Iterator method to get values of these key-value pairs, and then assign them to properties of Label2.
Delphi:
var
oDoc: TMongoDocument;
oIter: TJSONIterator;
Label2: TLabel;
....
oIter := oDoc.Iterator;
try
oIter.Next('Label1');
if (oIter.Key = 'Label1') and (oIter.&Type = TJsonToken.StartObject) then begin
oIter.Recurse;
oIter.Next;
Label2.Position.Y := oIter.AsInteger;
oIter.Next;
Label2.Position.X := oIter.AsInteger;
oIter.Next;
Label2.Text := oIter.AsString;
oIter.Return;
end;
finally
oIter.Free;
end;
C++Builder:
TLabel *Label2;
TMongoDocument *oDoc;
TJSONIterator *oIter = oDoc->Iterator();
__try {
oIter->Next("Label1");
//Label2->Text = "Starting ... " + oIter->Key;
if ((oIter->Key == "Label1") && (oIter->Type == TJsonToken::StartObject)) {
oIter->Recurse();
oIter->Next();
Label2->Position->Y = oIter->AsInteger;
oIter->Next();
Label2->Position->X = oIter->AsInteger;
oIter->Next();
Label2->Text = oIter->AsString;
oIter->Return();
}
}
__finally {
oIter->Free();
}