Dot notation

enonod

Well-Known Member
Licensed User
Longtime User
If I create a panel with views to be made visble or not like a Dialog, using a sub...
B4X:
Sub Items
Dim pItems as Panel
Dim eName,iQty As EditText
...
End Sub
I cannot refer to the EditText outside the sub as pItems.eName.Text
1. Is this still part of the rule that variables cannot be referred to outside their sub and I must again use Globals for all on the panel?

2. Please say Under what conditions I would use pItems.eName.Text because if they are Global I don't need the prefix?
 

gregmartin64

Member
Licensed User
Longtime User
If I create a panel with views to be made visble or not like a Dialog, using a sub...
B4X:
Sub Items
Dim pItems as Panel
Dim eName,iQty As EditText
...
End Sub
I cannot refer to the EditText outside the sub as pItems.eName.Text
1. Is this still part of the rule that variables cannot be referred to outside their sub and I must again use Globals for all on the panel?

2. Please say Under what conditions I would use pItems.eName.Text because if they are Global I don't need the prefix?


1 - It's part of the architecture, and not a rule. It's common across most object and event driven environments. Java itself does not allow it and ultimately, this tool compiles into Java.

2 Again, this is an object question, so the dot notation takes you down the parent/child object tree to give you access to objects that have exposed a method or property for you to use.

This is simplication and forgive this. But in the EditText component "object", a property is "text", so the parent of this property is EditText. The dot notation EditText.Text gets you to the text property of that object. Global is just another object, whereas a sub is a "method" or "event" that doesn't expose it's own variables as properties to other parts of the system.
 
Upvote 0

enonod

Well-Known Member
Licensed User
Longtime User
Thank you both
 
Upvote 0
Top