Android Question how to put a sub in a object

electro179

Active Member
Licensed User
Longtime User
I would put a sub in a tag
like that


tag is a object
NbrTotalPIDToSynchro is a sub

B4X:
pb.Tag = code_rdm.NbrTotalPIDToSynchro

thank you
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
It is not possible. You could create a custom Type containing ...

(Erel was faster šŸ˜„)

... containting the target (code_rdm) and the routine name.
Example:
B4X:
Type tToCall(Target As Object, SubName As String)



Dim ToCall As tToCall
ToCall.Initialize
ToCall.Target = "modXYZ"
ToCall.SubName = "Routine"
AnObject.Tag = ToCall



ToCall = AnObject.Tag
CallSub(ToCall.Target, ToCall.SubName)
 
Upvote 0

electro179

Active Member
Licensed User
Longtime User
when I use this function in activity : activity_firstsynchro

the

B4X:
function1 = "code_rdm.NbrTotalPIDToSynchro"

CallSub(Me,function1)

But I have an error
For input string : "null"
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
how do I have to declare ?
AnObject

pb.Tag = code_rdm.NbrTotalPIDToSynchro

I wrote AnObject as example... any object that has a property like Tag, which is of type object.

B4X:
Type tToCall(Target As Object, SubName As String)


Dim ToCall As tToCall
ToCall.Initialize
ToCall.Target = "code_rdm"
ToCall.SubName = "NbrTotalPIDToSynchro"
pb.Tag = ToCall


ToCall = pb.Tag
CallSub(ToCall.Target, ToCall.SubName)
 
Upvote 0

electro179

Active Member
Licensed User
Longtime User
I do that to test in the Sub Activity_Create(FirstTime As Boolean)

B4X:
    Dim obj As Object
    Dim pb As Panel
    pb.Initialize("")
    Dim ToCall As tToCall
    ToCall.Initialize
    ToCall.Target = "main"
    ToCall.SubName = "test"
    pb.Tag = ToCall
    ToCall = pb.Tag
    result = CallSub(ToCall.Target, ToCall.SubName)


B4X:
Sub test As Int
    
    Return 5
End Sub

and I have an enrror on the last line

the error is
java.lang.NumberFormatException: For input string: "null"
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
1586163627673.png


It can be used to call routines of "classes" (other objects) and services.
 
Upvote 0
Top