B4J Question About properties get & set.

amykonio

Member
Licensed User
Hi to everyone.
I have a class with two private strings declared in Class_Globals.
B4X:
Private ExportFolder As String
Private FtpExportFolder As String
Now I want to declare setters for those properties. This is what I do:
B4X:
public Sub setExportFolder(Value As String)
    ExportFolder = Value
End Sub

public Sub setFtpExportFolder(Value As String)
    FtpExportFolder = Value
End Sub
Now when i try to use those setters from another class, there is no autocomplete.
upload_2019-8-22_12-19-23.png

But if I type the commands they are accepted, and the application runs normally.
Is this an expected behavior?

(Working with B4J 7.51).

Andreas.
 

DonManfred

Expert
Licensed User
The Variable name and the subsignature overwrite itself.

Try name the internal vars like

B4X:
Private mExportFolder As String
Private mFtpExportFolder As String
and setters like

B4X:
public Sub setExportFolder(Value As String)
    mExportFolder = Value
End Sub

public Sub setFtpExportFolder(Value As String)
    mFtpExportFolder = Value
End Sub
 

amykonio

Member
Licensed User
Thank you both Erel and DonManfred.
After this change, now it shows ok.
upload_2019-8-22_12-41-14.png


But I'm a little confused about why these happened.
I saw DonManfred answer:
The Variable name and the subsignature overwrite itself.
So the getter or setter must have a different name from the property? I was thinking they was the property name with a set or get as prefix.

Andreas.
 

Attachments

DonManfred

Expert
Licensed User
So the getter or setter must have a different name from the property?
yes

A setter named setFtpExportFolder(Value As String) and the getter getFtpExportFolder() both point to FtpExportFolder which is a private property with the same name.
Give the getter and setter another name or rename the internal vars.
 

amykonio

Member
Licensed User
yes

A setter named setFtpExportFolder(Value As String) and the getter getFtpExportFolder() both point to FtpExportFolder which is a private property with the same name.
Give the getter and setter another name or rename the internal vars.
Ok.
Thank you.
Now it's clear.

Andreas.
 
Top