Bug? Compile time object cast error

ANC Software

New Member
Licensed User
Longtime User
Hello,

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

B4X:
Sub GetTextItem(Rec As Map, FieldName As String) As 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:

B4X:
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
 

Erel

B4X founder
Staff member
Licensed User
Longtime 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.

Further, I noticed that in this case the Application_Error didn't fire.
Make sure to run your app in release mode. If it doesn't work then please start a new thread in the questions forum.
 
Top