Topic
  • 2 replies
  • Latest Post - ‏2014-04-10T19:07:09Z by llandale
Tap5
Tap5
1 Post

Pinned topic realOf error "incorrect argument"

‏2014-04-09T19:21:10Z |

When using the code below we get the following error "-E- DXL: <Line:5> Incorrect argument for function (realOf)".  Can anyone tell me what is wrong with line 5?

real calcCost(Object o){

  real rAccCost = 0.0

  Object objChild = null

  for objChild in o do {

      rAccCost += realOf(objChild."Cost") 

      rAccCost += calcCost(objChild)

  }

  return rAccCost

}

real r = calcCost(obj)

if(r > 0.0) obj.attrDXLName = r

  • SudarshanRao
    SudarshanRao
    39 Posts

    Re: realOf error "incorrect argument"

    ‏2014-04-10T07:38:09Z  

    Suffix the attribute with a blank string, that I think should do the trick. So your fifth line should be:

    rAccCost += realOf(objChild."Cost" "")

  • llandale
    llandale
    2986 Posts

    Re: realOf error "incorrect argument"

    ‏2014-04-10T19:07:09Z  

    Suffix the attribute with a blank string, that I think should do the trick. So your fifth line should be:

    rAccCost += realOf(objChild."Cost" "")

    Yes.

    Discussion:

    • obj.NameAttr returns a variable of type "Attr__" (which we don't use)
    • realOf(Variable) requires Variable to be type "string" or "int"; but in your case its getting a variable of type "Attr__" and thus the error.
    • string s = obj.NameAttr works because there is a DXL "perm" of an equal sign which gets the value of that attribute and sets it to the string.
      • string = Attr__
    • Attr__ ""  uses the concatenate perm, which retrieves the value from the attribute and converts it to a string.
    • string s = obj.NameAttr "" uses a different equal sign perm; first retrieving the value, converting to a string, THEN assigning it to s.
    • Another time you must concatenate an Attr__ with a string is in "if" statements:
      • if (obj.NameAttr "" == "Whatever") then..

    It is indeed confusing.  In general, routinely use double quotes after o.NameAttr to make it work; except during assignment statments.

    -Louie