You are not logged in.
Pages: 1
Hi
I receive this from mongoDB command:
res: (variant) =
{"set":"rs0",
"date":"2014-09-29T14:11:35",
"myState":1,
"members":
[
{"_id":0,"name":"127.0.0.1:27019"},
{"_id":1,"name":"192.168.172.130:27018"},
{"_id":2,"name":"192.168.172.130:27020"}
],
"ok":1}
How to read "members" ?
log('Set_ID: '+res.set); //<-- this works
with TDocVariantData(res.members) do
begin
for i := 0 to Count-1 do // <--- count 0
log(Values[i].name); // <--- no output
end;
Offline
this works
for i:=0 to res.members._Count-1 do
begin
log(inttostr(res.members._(i)._id)+': '+res.members._(i).name);
end;
but,
Why the version of the previous post wrong?
Offline
DocVariantDataSafe ?
But how ?
Offline
Something like this:
with DocVariantDataSafe(res.members)^ do
begin
for i := 0 to Count-1 do // <--- count 0
log(Values[i].name); // <--- no output
end;
In fact, properties are returned as varByRef when late-binding is used, for performance.
TDocVariantData(res.members) won't work, whereas DocVariantDataSafe()^ will follow varByRef redirection.
Offline
Pages: 1