FireDAC.Phys.MongoDBWrapper.TMongoDocument.Iterator
Delphi
function Iterator: TJSONIterator;
C++
System::Json::Builders::TJSONIterator* __fastcall Iterator();
Propriétés
Type | Visibilité | Source | Unité | Parent |
---|---|---|---|---|
function | public | FireDAC.Phys.MongoDBWrapper.pas FireDAC.Phys.MongoDBWrapper.hpp |
FireDAC.Phys.MongoDBWrapper | TMongoDocument |
Description
Crée une nouvelle instance et renvoie une référence à un itérateur JSON.
REMARQUE : L'appelant de cette méthode doit libérer l'objet itérateur après son utilisation.
Exemples
Imaginez le scénario suivant :
- Vous avez ajouté un document à un ensemble de données MongoDB en utilisant l'exemple de code de BeginObject.
-
- Ce document contient le champ Label1 qui comporte un document incorporé avec trois paires clé-valeur : "Top": 30, "Left": 30, et "Caption": "Enter value:".
- Vous avez déposé un libellé (référencé comme la variable Label2 du type TLabel dans notre exemple) sur votre fiche d'application.
L'extrait de code suivant illustre l'utilisation de la méthode Iterator pour obtenir les valeurs de ces paires clé-valeur, puis les assigne aux propriétés de 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();
}