3

I'm using SuperObject to work with Json/Delphi I have a function that take a string and create a var superobject type, I need to check if it has an object (in my case is 'smtp') and if it don't, i create. The problem is: 'smtp' has children, example smtp.address and I have to create smtp and all its children, but my function doesn't work.

My Code:

if js.o['smtp'] = nil then
  js.o['smtp'].S['address']:= 'justATest';

Can anyone help me?

I'm using Delphi 2007 with SuperObject Unit

Jan Doggen
  • 8,799
  • 13
  • 70
  • 144
  • I know nothing about SuperObject but I would've thought that if js.o['smtp'] = nil then trying to access a member of that (js.o['smtp'].S) is going to give you an access violation? – Stuart May 25 '11 at 14:25
  • not really, 'cause if I create a fake 'smtp' with children, it works – Jaqueline Duque May 25 '11 at 14:39
  • Then create a fake smtp. What Stuart was saying is that in the code above, you don't create any smtp at all, so *of course* your code fails when it tries to access the `S` member. There is no smtp object at all, so there is not `S` member to access. Create the smtp object, and *then* start setting its properties. – Rob Kennedy May 25 '11 at 15:45

1 Answers1

4
if js['smtp'] = nil then
  js.S['smtp.address']:= 'justATest';
Henri Gourvest
  • 989
  • 8
  • 12
  • @Henri Gourvest: Can you do a favour considering this unanwsered [question](http://stackoverflow.com/q/7841617/744588) (Pour l'amour du ciel). – menjaraz Jan 05 '12 at 17:47