B4J Question [BANano] nomenclature of banano?

xulihang

Active Member
Licensed User
Hi there,

I come across a naming problem with banano. I have a global variable named pageNum, which is an integer. But a compenent's id is also pagenum. There will be a conflict.

Also, I have a sub named "Search" (my app is also named search). I will have this error:

B4X:
app1552469813553.js:9 Uncaught TypeError: self is not a function
    at banano_search.searchbutton_click
So I changed it from "Search" to "DoSearch".

Is there a nomenclature of banano that we should pay attention to?
 

alwaysbusy

Expert
Licensed User
Thanks, here are my findings:

1. In the main you cannot use a method name that has the same name as your project. B4J would give you an error too if you would make a method Main() for example. In BANano, Main is a special case as it uses not 'Main' as the javascript class, but the project name (search in your case).

A similar effect in can be seen in normal B4J if you create a new class 'test' with this code:

B4X:
Sub Class_Globals
   Private fx As JFX
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
   
End Sub

public Sub test() '<--- this will turn red
   
End Sub
2. Because you use the same names in the layout as the code (for a different variable), this will happen. If you use the generate members menu in the designer, this would've given you:

B4X:
Private pageNum As SKTextBox
Private pageNum As Int=1
B4J would've given you an error too.

So the conclusion is:
1. In Main, don't use a method named the same as your project
2. In layouts, maybe using a prefix for your components could be a good rule of thumb. E.g. give them a prefix of the type like txtPageNum (this is something I always try to do as the name then gives me an indication of what type of component I'm dealing with).

Thanks for reporting this! Unfortunately there is not much I can do about it. :( This could be a good topic to bookmark (I will!), as these errors can be something that is not immidiately obvious.

I'll add it to the download post too.
 
Top