Bug? Properties

LucaMs

Expert
Licensed User
Longtime User
It is not a real bug, but it is a ... uhm... "an incorrect behaviour".

In a Class I have a property, setSomething(what as int).

The editor, rightly, does not list setSomething as available method ("intellisense") although it is also a public routine but if you use it like a method (objMyClass.setSomething(12)) it works; instead, this should be an error reported by the compiler, I think.

[P.S. or/and Syntax error]
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
I was hoping to have explained well :( :)

If you had a Class like:

clsPerson
B4X:
Sub Class_Globals
    Private mName As String
End Sub

Public Sub setName(Name As String)
    mName = Name
End Sub

Public Sub getName As String
    Return mName
End Sub


Name would be a Property, then you should set its value using:
B4X:
Dim Person As clsPerson
Person.Initialize
Person.Name = "Klaus"
Person.setName("Erel") ' this should not work, and it should show an error.
 

LucaMs

Expert
Licensed User
Longtime User
I agree with Klaus. This is good for compatibility with old code.

There is another delicate point here. You must use setName inside the class to call the method (and it will show in the autocomplete list). So I don't see any harm if someone also uses this syntax from a different module.

In fact, most likely this is not a problem.

I happened to talk to a person about a method that from my point of view does not exist.

However, inside the class you should not call the property but set the member variable associated with it.

As for compatibility (somewhat dated) any methods whose name begins with "set" should simply become "Set ..." in the old projects (a replace would be enough).


This is only a formal question, of course.
 
Top