Ok, it looks like there were two things happening at once here.
1. The extreme User case where the JSON document's metaData.fields array is actually empty.
Where the array is empty it seems in FP you can not test on myJsonArray.count expecting 0
2. and the inappropriateness of direct assignment of the metaData TJSONObject
It'd work the first time, but when the dataset changes upon opening another JSON document, this will be nulled it seems; so the second use of it in a session will fail.
Maybe it is for scope, or some other reason - I do not yet grasp the underlying "wiring" of the JSON dataset. Whatever I must have been assuming the object was being shared by Value when it appears to actually be passed by Reference equivalence.
So I am testing the following, and so far it seems stable.
It copes with an old JSON document where any field is missing in metaData.fields, and the extreme User case where for some reason, there are no fields at all, and it avoids direct assignment of the JSON object...
if (dataset_fields_Array.IsNull = true)
or
(dataset_fields_Array.Count
<> Const_btabb_tamplate_metadata_fields.Count) then
fDataset.MetaData := GetJSON(Const_btabb_tamplate_metadata.AsJSON,true)
as TJSONObject;
Any thoughts - anything else I should be aware of please?
Paul