Bug? DuckTyping

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
I get an error when calling something like this:

B4X:
    For Each n As Node In MainForm.RootPane.GetAllViewsRecursive
       ' i would like to use a combination of subExists and callsub
        If n Is TextField Or n Is TextArea Then
            callsub2(n,"setText","")
        End If
    Next

The first error is that the IDE says that there is not sub with that name
Second is that it fails, it mentions that textfield cannot be converted to string.

ducktyping only works for Classes created within the IDE?

right now i am using javaObject:

B4X:
    For Each n As Node In MainForm.RootPane.GetAllViewsRecursive
        If n Is TextField Or n Is TextArea Then
            Dim nJo As JavaObject = n
            nJo.runmethod("setText",Array(""))
        End If
    Next

Thanks!
 

Cableguy

Expert
Licensed User
Longtime User
The callsub methods expect a class ref where to search the sub, not a node...

You could however use that approach if you use it with the tag property

Each tag property should hold the node name and the use:
Callsubdelayed(me,n.tag&"_setText","")
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Thank you CableGuy, that is actually a nice approach.

But to correct you... technically a node is a class.
 

Cableguy

Expert
Licensed User
Longtime User
Thank you CableGuy, that is actually a nice approach.

But to correct you... technically a node is a class.
The thing is, nodes are java classes, not b4j, and callsub is a B4J only kind of feature so it has its limitations or particularities
 
Top