Bug? Compile time object cast error

Discussion in 'Bugs & wishlist' started by ANC Software, May 7, 2018.

  1. ANC Software

    ANC Software New Member Licensed User

    Hello,

    I have a sub which helps me to read map objects as follows:

    Code:
    Sub GetTextItem(Rec As Map, FieldName As StringAs String
     
    Dim ret As String
     ret=
    ""
     
    Try
      ret=DecodeString(Rec.Get(FieldName))
     
    Catch
      
    Log("GetTextItem")
     
    End Try
     
    Return ret
    End Sub
    The problem is that if I call GetTextItem passing a List object instead of a Map object, the compiler doesn't warn me about the error, but it will be thrown at Runtime.

    Example:

    Code:
    dim ls as List

    ls.initialize
    'add some items

    log( GetTextItem(ls, "DUMMY") ) ' this should be handled by the compiler
    Further, I noticed that in this case the Application_Error didn't fire.

    Any help is much appreciated, thank you.
    Antonello
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    In some cases the compiler will show a warning for wrong types, however there are many cases where the compiler doesn't know whether casting is allowed so it tries to cast. In such cases the error will happen at runtime.

    Make sure to run your app in release mode. If it doesn't work then please start a new thread in the questions forum.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice