G GuyBooth Active Member Licensed User Longtime User Dec 13, 2017 #1 Looking at the 7.80 Beta release notes, it looks as if I can simplify my code: Was: B4X: If SubExists(module, Subname) Then CallSubDelayed(module,SubName) Can now simply be: B4X: CallSubDelayed3(module,SubName) without throwing a runtime error. Will it start the called module if it is not running, even if the Sub doesn't exist? Is this also true with CallSub (and has it always been true)?
Looking at the 7.80 Beta release notes, it looks as if I can simplify my code: Was: B4X: If SubExists(module, Subname) Then CallSubDelayed(module,SubName) Can now simply be: B4X: CallSubDelayed3(module,SubName) without throwing a runtime error. Will it start the called module if it is not running, even if the Sub doesn't exist? Is this also true with CallSub (and has it always been true)?
Erel B4X founder Staff member Licensed User Longtime User Dec 13, 2017 #2 GuyBooth said: Will it start the called module if it is not running, even if the Sub doesn't exist? Click to expand... It will start the activity or service if it is not currently running. If it is problematic then you need to check it with SubExists. GuyBooth said: Is this also true with CallSub Click to expand... CallSub never starts the target module. Upvote 0
GuyBooth said: Will it start the called module if it is not running, even if the Sub doesn't exist? Click to expand... It will start the activity or service if it is not currently running. If it is problematic then you need to check it with SubExists. GuyBooth said: Is this also true with CallSub Click to expand... CallSub never starts the target module.
G GuyBooth Active Member Licensed User Longtime User Dec 13, 2017 #3 Erel said: CallSub never starts the target module. Click to expand... Sorry, yes I understand that. I meant this to be part of the first question - in other words, if I use the code "CallSub" and the sub doesn't exist, will it throw a runtime error? Upvote 0
Erel said: CallSub never starts the target module. Click to expand... Sorry, yes I understand that. I meant this to be part of the first question - in other words, if I use the code "CallSub" and the sub doesn't exist, will it throw a runtime error?
Erel B4X founder Staff member Licensed User Longtime User Dec 14, 2017 #4 CallSub will throw an error if the target module is a class. In other cases it won't. The reason behind it is that CallSub can be used for "duck type interfaces" where you have multiple classes with one or more identical methods. B4X: For Each o As Object In ListOfShapes CallSub(o, "DrawYourself") Next It is a programming mistake to add an object to this list that doesn't implement the DrawYourself sub. Note that there is a special optimization for this usage (in release mode). Upvote 0
CallSub will throw an error if the target module is a class. In other cases it won't. The reason behind it is that CallSub can be used for "duck type interfaces" where you have multiple classes with one or more identical methods. B4X: For Each o As Object In ListOfShapes CallSub(o, "DrawYourself") Next It is a programming mistake to add an object to this list that doesn't implement the DrawYourself sub. Note that there is a special optimization for this usage (in release mode).