Bug? Constants 'leak'

mikecthompson

New Member
Licensed User
Longtime User
An error occurs depending on the order of Dim statements for Const.
The first code below creates an error:
B4X:
Sub getViewType()As String
    Dim r As Reflector
    Dim strTemp As String
    Dim Const strAndroidStuff As String = "android.widget."
    Dim intEnd As Int
   
    r.Target=innerView
    strTemp = r.RunMethod("toString")
    intEnd=strTemp.IndexOf("(")
    strTemp = strTemp.SubString2(strAndroidStuff.Length+1,intEnd)
   
    Return strTemp
End Sub

The line "strTemp = r.RunMethod("toString")" generates an error: "Cannot set a Const variable".

Moving the line "Dim strTemp As String" to go below the "Dim Const ..." removes the error:
B4X:
Sub getViewType()As String
    Dim r As Reflector
    Dim Const strAndroidStuff As String = "android.widget."
    Dim strTemp As String
    Dim intEnd As Int
   
    r.Target=innerView
    strTemp = r.RunMethod("toString")
    intEnd=strTemp.IndexOf("(")
    strTemp = strTemp.SubString2(strAndroidStuff.Length+1,intEnd)
   
    Return strTemp
End Sub

I have not investigated further on the behaviour in different parts of the code, however, this 'bug' appears constantly (pun intended).

PS - I have not run this code yet as the bug appeared, so please focus on the syntax and not the content.
 
Top