iOS Question Callsub using string-based module name

Jack Cole

Well-Known Member
Licensed User
Longtime User
Using b4a, I can call a sub in a different module based on the string name of the module (say CallSub("SomeActivity", "SomeSub"). This is deeply integrated into many of my Android apps. I'm trying to port apps to b4i and discovered that CallSub will not allow the module name to be a string (it is expecting an Object). Is there a way to programmatically call a sub in another module based on the string-based name of the module in b4i?
 

Jack Cole

Well-Known Member
Licensed User
Longtime User
I figured out one way to do it, but I wonder if there is a more direct way of doing it. This way, I store a mapping of the string names to the module objects.

B4X:
dim m as Map
m.Initialize
m.Put("TestActivity",TestActivity)
CallSub(m.Get("TestActivity"), "TestSub")
 
Last edited:
Upvote 0

sorex

Expert
Licensed User
Longtime User
maybe you can use callSub2/callsub3 and use the parameters to pass your strings to a common function where you do the rest with select/case?

you'll keep the one liners and the rest is at one place.
 
Upvote 0

Jack Cole

Well-Known Member
Licensed User
Longtime User
Maybe a combination of your idea and mine would be even better. Use CallSub3 to call a routing sub in a code module. The routing sub would have a map like the one I describe above. This routing sub would then use CallSub2 to pass all the parameters as a map.

B4X:
CallSub3(RouterModule, "RouteCallSub", "TestActivity", CreateMap("Sub":"TestSub","Param1":"TestVal","Param2":"TestVal2"))

Sub RouteCallSub(ModuleName as String, Params as Map)
    CallSub2(ActivityMap.Get(ModuleName), Params.Get("Sub"), Params)
End Sub
 
Upvote 0
Top