The rules for properties:
- Only relevant for classes.
- One or two subs with the format get<prop> / set<prop>. Note that get / set must be lower case.
- A property can be read-only (only get), write-only (only set) or both.
- The two subs types (parameter in the set sub and return type in the get sub) must be the same.
- Within the class you should call the methods directly. The property will not appear.
- The property cannot have the same name as a global variable.
"Within the class you should call the methods directly. The property will not appear."
I don't see why we can't reference the property name in the class module like we can in other modules.
If I have a property:
I can reference MyClass.FullName in any module except its own class module. In the Class module I have to use getFullName and not FullName. Why can't the compiler resolve FullName to getFullName or setFullName as required? I find it awkward using 2 sets of naming conventions to reference the same property.
In the class module I have to use:
setFullName("George Smith")
but in other modules I use:
FullName = "George Smith"
- Only relevant for classes.
- One or two subs with the format get<prop> / set<prop>. Note that get / set must be lower case.
- A property can be read-only (only get), write-only (only set) or both.
- The two subs types (parameter in the set sub and return type in the get sub) must be the same.
- Within the class you should call the methods directly. The property will not appear.
- The property cannot have the same name as a global variable.
"Within the class you should call the methods directly. The property will not appear."
I don't see why we can't reference the property name in the class module like we can in other modules.
If I have a property:
B4X:
public Sub getFullName
return FirstName & " " & LastName
end
I can reference MyClass.FullName in any module except its own class module. In the Class module I have to use getFullName and not FullName. Why can't the compiler resolve FullName to getFullName or setFullName as required? I find it awkward using 2 sets of naming conventions to reference the same property.
In the class module I have to use:
setFullName("George Smith")
but in other modules I use:
FullName = "George Smith"
Last edited: