Huh? The private designation is for OUTSIDE access to the global variables of a class, not internal access.This happens only inside the class itself (but anyway it shouldn't)
In that "example" (image) I wasn't try to access the variable (directly) but an object of that type.Huh? The private designation is for OUTSIDE access to the global variables of a class, not internal access.
Well, it shouldn't work that way.Even java does this (allow access to private within the same class). Attaching demo files.
Yes, VB Net tooWell, it shouldn't work that way.
I'll try VB Net (unfortunately it needs half an hour to start up!)
If it didn't work that way you wouldn't be able to access it from anywhere. The idea of a private item is that you can use it within a class but it cannot be seen outside which reduces possible confusion as to what the public interfaces to the class are. Subs and variables in a class should all be private except those that you want the outside world to be able to twiddle with.Well, it shouldn't work that way.
Public Sub MsgFrom (SenderPerson As clsPerson, Msg As String)
' Here I shouldn't be able to access SenderPerson.[any private member]
End Sub
No. I suppose B4X would be very angry ?Have you tried making Class_Globals private ?
eg,
B4X:Private Sub Class_Globals ... End Sub
You mean that it shouldn't be accessible to another instance of the same class, but only to the instance that contains the property.Maybe I did not say it clear enough; try again.
Suppose you have a clsPerson class, which has a public method:
B4X:Public Sub MsgFrom (SenderPerson As clsPerson, Msg As String) ' Here I shouldn't be able to access SenderPerson.[any private member] End Sub
Exactly.You mean that it shouldn't be accessible to another instance of the same class, but only to the instance that contains the property.
Tried. B4X doesn't get mad ?, it compiles and works.Have you tried making Class_Globals private ?
eg,
B4X:Private Sub Class_Globals ... End Sub
You have got to allow access to private variables from public Subs otherwise your class will be divided into public things and private things and the private things will be of no use at all as they cannot accept values from the public side. By only letting the outside world access public things you can control what they can and can't do to your class. Inside the class you can do whatever you want with both public and private things.Suppose you have a clsPerson class, which has a public method:
Classes tutorial | B4X Programming ForumClass_Globals - This sub is similar to the activity Globals sub. These variables will be the class global variables (sometimes referred to instance variables or instance members).
also C++, TypeScript, C# etc. Sorry but we have 50 years of computer science and language design which has established these norms.So, we have seen that this is the case in B4A, B4J (I assume also B4i), Java and VB Net.