Narinder: I just ran the code you posted on 17R4 (Mac and Windows) and I’m getting an error message - “Object or a Collection expected”
After the code completes execution, has 4D created .bar dynamically? -- Douglas von Roeder 949-910-4084 On Fri, Sep 20, 2019 at 11:02 AM Narinder Chandi via 4D_Tech < 4d_tech@lists.4d.com> wrote: > So, I am writing some code and using C_OBJECT. Using the following > contrived object as an example: > > C_OBJECT($object) > $object:=New object > $object.foo:=New object > $object.foo.foo1:="foo1" > $object.foo.foo2:="foo2" > $object.bar:=New object > $object.bar.bar1:="bar1" > $object.bar.bar2:="bar2" > > The code executes as expected. Sometimes I might accidentally forget to > initialise a nested object - it happens! So, if I replace the above with: > > C_OBJECT($object) > $object:=New object > $object.foo:=New object > $object.foo.foo1:="foo1" > $object.foo.foo2:="foo2" > $object.bar.bar1:="bar1" > $object.bar.bar2:="bar2" > > i.e. I forget "$object.bar:=New object" then the code will silently fail. > Can somebody tell me why the interpreter does not raise an error in this > situation? This was tested with 17.1 and 17.2 on Mac and the behaviour was > the same (i.e. silent code failure) in both versions. > > In the docs for C_OBJECT: > https://doc.4d.com/4Dv17/4D/17.3/C-OBJECT.301-4621707.en.html > it states: > "Important: The C_OBJECT command does not create an object named variable. > If you want to access the properties of the object itself using object > notation, you must first initialize it using the New object command, > otherwise a syntax error is returned (see example)." > > That doesn't seem to be the case - no syntax error is raised and the code > also compiles?! Can somebody point out what I am missing here? Thanks. > > Regards, > > Narinder Chandi, > ToolBox Systems Ltd. > > I am available for new consulting opportunities… > http://4d.1045681.n5.nabble.com/ANN-4D-Developer-Available-td5765443.html > -- > > > ********************************************************************** > 4D Internet Users Group (4D iNUG) > Archive: http://lists.4d.com/archives.html > Options: https://lists.4d.com/mailman/options/4d_tech > Unsub: mailto:4d_tech-unsubscr...@lists.4d.com > ********************************************************************** ********************************************************************** 4D Internet Users Group (4D iNUG) Archive: http://lists.4d.com/archives.html Options: https://lists.4d.com/mailman/options/4d_tech Unsub: mailto:4d_tech-unsubscr...@lists.4d.com **********************************************************************