[JPR]
> From: David Adams <[email protected]>
Hi David,
> but he doesn't seem to have had time to respond.
OK, I apologize ;-) But in fact, I do not have time...
Before giving some explanations, I would like to point out that while Objects
are widely used in DB4D and Wakanda, this concept is pretty new in 4D, and
needs time to evolve and develop. Rome wasn't built in a day, and Objects are
deeply transforming the very heart of 4D. So you may expect each new version to
bring up new features, new possibilities, and new visions of thinking and
programming your future applications.
> As far as I can tell, 4D can store a wide range of data types in an
> "object" container. As Rob pointed out, internally this is a hash table.
Exactly, this is what I explained in my previous post about associative arrays.
> As
> far as I can find, the internals aren't described anywhere.
You're right, internals aren't described, and will not be, for we need to keep
room for evolution, so internal will change as they are already changing very
often. As soon as we publish a description of the internal handling, Devs begin
to use it and to complain at every new change...
> For reference, all of my root objects are from JSON Parse ("{}")
You can do that, but I don't see the absolute need for it.
> Dot Notation
It will come, and not in a far future. And it's very powerful.
> Count Elements
This also, but just from this simple demand, you may understand how complex it
can be. Count what ? Every property ? Every sub-property ? On how many levels ?
Including the arrays' sizes ? The question is : What do you want to count, and
how? Obviously, today, the OB GET PROPERTY NAMES does the job, and recursivity
is fun, isn't it?
> Again, huh? I don't see how you can scan an object generically and explore
> its contents.
I did it for the Component I've made for the 2016 training and the 2017 Tour
(Look into CustomObjectField.4dbase). Just by getting recursively lists of
properties from OB GET PROPERTY NAMES($obj; $arNames; $arTypes) You have it in
the examples I've given during the Sydney's training.
> Blind Iteration
The OB GET PROPERTY NAMES($obj; $arNames; $arTypes) gives you the type of each
property. The problem comes with the Arrays, for it just tell you that the type
is Object Array. Every array have the same type. The 1st thing to do is to know
if it's an array of Objects. For this, try this code:
OB GET ARRAY($objectPtr->;$arrProperties;$arrValues)
$sizeArray:=Size of array($arrValues)
If ($sizeArray>0)
If ($arrValues{1}="[object Object]") //array of Objects
Else // Other array
End if
End if
Now, for other arrays, you have different cases:
1- You put the array in the object, so you know what kind of array. You can use
different tricks to save the type inside the array itself (like the 'zero'
element) or to add to your object, an object which is the description of the
object itself, or any other trick (as long as it works...)
2- It's an array coming from outer space, then you cannot 'know' the type, for
it may have different types in it. You will see in a (near) future that 4D will
handle the JSON Array type, in which each element may have a different type.
Instead of the type of the array, you will have to check the type of each
individual element.
3- It's an array created by the User. Unless you got Users able to enter
directly Objects with the JSON syntax, it has to go through your code, then
case 1-
> and seemingly avoiding access to the underlying tree structure of the JSON.
You can always switch back and forth between the Object and it's JSON
representation, so I don't see the point...
> The object and JSON commands are great features, but it really puzzles me
> that the seem incomplete...
You are right! Because it IS incomplete! But wait a little bit, and you will
see huge evolutions...
Hope this helps,
My very best,
JPR
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ: http://lists.4d.com/faqnug.html
Archive: http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub: mailto:[email protected]
**********************************************************************