Android Question (Solved)How to Get/Set the properties of objects that are hold in a List.

opus

Active Member
Licensed User
Longtime User
I'm trying to Get/Set the properties of objects that are hold in a list.

My Objects are declared like (in Class module "Stapel"):
B4X:
Sub Class_Globals
.....
   Private mLeft As Int 'Left-Koordinate des Stapels
.... 
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize( Left As Int)
....
   mLeft=Left
..... 
End Sub
'I made those "get.." and "set.." as written in the Guide, whowever I can't get the properties as written!
Sub getmLeft As Int
   Return mLeft
End Sub

Sub setmLeft(Left As Int)
   mLeft=Left
End Sub
The List is declared like:
B4X:
Sub Process_Globals
Dim mStapel As Stapel
End Sub

Each object is intialized and added successfully.
The only way I could get/set the properties is like that:
B4X:
For i=0 To 9
     Dim lStapel As Stapel 
     lStapel=mStapel.Get(i)'get a local copy of the object
     lStapel.setmLeft(1%x+i*(KartenBreite+1%x)) 'set its property
     mStapel.Set(i,lStapel)  'put it into the list   
Next
Isn't there a more direct way? And why do I need to use the .setmLeft Sub at all, the Guide said I could use .mLeft directly to get or set?

Bear with my, I'm still new to B4A, got my licence an houre ago!
 

thedesolatesoul

Expert
Licensed User
Longtime User
I am not sure, sometimes it doesnt convert to properties, but my guess it is due to your 'case'.
Consider renaming it to getMLeft and setMLeft.
Also, you do not need to set the item back into the list. You should be able to bring this down to:

B4X:
For each lStapel as Stapel in mStapel
       lStapel.MLeft = (1%x+i*(KartenBreite+1%x))
Next

EDIT:
In fact I added the following to my class and it detected it as a property:

B4X:
Sub getmLeft As Int
    Return 1
End Sub

Sub setmLeft(Left As Int)

End Sub

So it does seem to work.
 
Upvote 0

socialnetis

Active Member
Licensed User
Longtime User
Isn't there a more direct way? And why do I need to use the .setmLeft Sub at all, the Guide said I could use .mLeft directly to get or set?
In the tutorial it says that the property cannot have the same name as a global variable, so you should rename the get/set to for example something like getLt/setLt or change the variable name mLeft to something like "theLeft" (try not to use the "Left" word if is a View because it will confuse the Left property of the view)
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
B4X:
Sub Class_Globals
   Private mLeft As Int ' Left-Koordinate des Stapels
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(Left As Int)  ' <--- this is not needed, of course, but can be useful
   mLeft=Left
End Sub

Sub getLeft As Int
   Return mLeft
End Sub

Sub setLeft(Left As Int)
   mLeft=Left
End Sub
 
Upvote 0

opus

Active Member
Licensed User
Longtime User
Thanks for the replys.
I didn't know For each was useable in B4A, I'll try that tonight.
I will also try all the other hints regarding the property.

I will soon get head head turned from VB.NET to B4A using all this feedback.

Is there a limit to "static"gifs for an avatar, since my nonstatic one is showing only in the picking dialog?
 
Upvote 0

opus

Active Member
Licensed User
Longtime User
Thanks for the inputs!
I got the "For each .." working (big help)
Need to look into the property (have to delay that)

..and changed my avatar to be visible/static.

Closing this one!
 
Upvote 0
Top