iOS Code Snippet CallSub with ANY number of parameters

B4X:
Sub CallSubX (Component As Object,SubName As String,Params() As Object)
    Dim no As NativeObject=Component
    Dim name As String=SubName
    Dim ll As List
    ll.Initialize2(Params)
    For i =0 To Params.Length-1
        name=name & ":"
    Next
    no.GetField("bi").RunMethod("raiseUIEvent:event:params:",Array(Null,name,ll))

   
End Sub


Example usage

B4X:
CallSubX (Me,"event_event",Array(1,"abc",3,"def",5)

Sub event_event(a as int, b as string, c as int, d as string, e as int)

Log(b)

End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I don't recommend using this code. CallSub is treated in a special way by the compiler.

If you need to pass multiple parameters to a sub that called with CallSub then change its signature to:
B4X:
Sub MySub (Params() As Object)
And call it with:
B4X:
CallSub(Me, "MySub", Array(1, 2, 3, 4))

Or pass a custom type or a Map created with CreateMap.
 
Top