Alessandro71 Well-Known Member Licensed User Longtime User Mar 28, 2021 #1 Is there a way to use a Sub as an Object? Actually I'm using some code like this: B4X: Select index Case 1 function_a Case 2 function_b Case 3 function_c End Select I'm wondering if I could create a map like this B4X: Dim functionmap As Map = CreateMap( _ 1: function_a, _ 2: function_b, _ 3: function_b _ ) so it would be possible to select the right Sub only by a Get and calling it
Is there a way to use a Sub as an Object? Actually I'm using some code like this: B4X: Select index Case 1 function_a Case 2 function_b Case 3 function_c End Select I'm wondering if I could create a map like this B4X: Dim functionmap As Map = CreateMap( _ 1: function_a, _ 2: function_b, _ 3: function_b _ ) so it would be possible to select the right Sub only by a Get and calling it
LucaMs Expert Licensed User Longtime User Mar 28, 2021 #2 If you call them using CallSub or CallSubDelayed, you can. CallSub(YourObject, mapSubs.Get(...)) Upvote 0
Alessandro71 Well-Known Member Licensed User Longtime User Mar 28, 2021 #3 Do I have the side effect of the Sub being actually called only at the next event loop iteration instead of being called immediately? Upvote 0
Do I have the side effect of the Sub being actually called only at the next event loop iteration instead of being called immediately?
LucaMs Expert Licensed User Longtime User Mar 28, 2021 #4 Alessandro71 said: Do I have the side effect of the Sub being actually called only at the next event loop iteration instead of being called immediately? Click to expand... None Upvote 0
Alessandro71 said: Do I have the side effect of the Sub being actually called only at the next event loop iteration instead of being called immediately? Click to expand... None
Alessandro71 Well-Known Member Licensed User Longtime User Mar 28, 2021 #5 I see that CallSub can't be used for Code modules (that's my use case) It's also not clear if I can get the return value of the called Sub Upvote 0
I see that CallSub can't be used for Code modules (that's my use case) It's also not clear if I can get the return value of the called Sub
LucaMs Expert Licensed User Longtime User Mar 28, 2021 #6 Alessandro71 said: I see that CallSub can't be used for Code modules (that's my use case) It's also not clear if I can get the return value of the called Sub Click to expand... You can "transform" your code module to a class module. Create a new class, move all stuff (variables, subs) to this class. Once you have an instance of that class (a variable), you can call its sub as wrote and get results. Dim Result As Int = CallSub2(InstanceName, mapSubs.Get("MyRoutine"), 5) Upvote 0
Alessandro71 said: I see that CallSub can't be used for Code modules (that's my use case) It's also not clear if I can get the return value of the called Sub Click to expand... You can "transform" your code module to a class module. Create a new class, move all stuff (variables, subs) to this class. Once you have an instance of that class (a variable), you can call its sub as wrote and get results. Dim Result As Int = CallSub2(InstanceName, mapSubs.Get("MyRoutine"), 5)