开发者

Don't understand "Object required" error

I have the following ASP classic function:

function get_children(n)
  dim local_array
  dim parent
  dim path
  if n.hasChildNodes() then
    for each child in n.childNodes
      local_array = array_merge(local_array, get_children(child))
    next
  else
    set parent = n.parentNode
    while isobject(parent)
      path = parent.nodeName & "/" & path
      set parent = parent.parentNode
    wend
    path = path & "/" & get_attr(n, "file")
    set_attr n, "path", path
开发者_运维知识库    local_array = Array(0)
    set local_array(0) = n
  end if
  get_children = local_array
end function

Running this over an XML node (coming from a Microsoft.XMLDOM object), I get the error Object required: 'parent' on the line

path = parent.nodeName & "/" & path

and I can't understand why. I'm checking isobject. Can anyone explain what the runtime is complaining about, and why?


When there is no more parent nodes, you will get a null value back, i.e. Nothing. However, Nothing is the "null object", so it's also an object. The value of IsObject(Nothing) is True.

Check for Nothing instead of checking if the variable contains an object:

while not (parent is Nothing)


I'm not 100% sure, but maybe you should use something with/instead if IsObject? I suggest to try IsEmpty(), IsNull() or Is Nothing. The latter is used like this:

If Not (myObject Is Nothing)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜