Android Question (Solved) Get or Set Properties if they are List-Items

opus

Active Member
Licensed User
Hi, this questions seems to be same as my last one however it is a bit deeper into properties.

I have an Object declared with a properties like:

B4X:
'Class module
Sub Class_Globals
   Private mKarten As List 'will recieve clKarte-Items
   Private mTop As List 'will recieve Int for the Top-value of each clKarte-Item
 ....
End Sub

Public Sub GetSingleKarte(Index As Int) As clKarte
   Return mKarten.Get(Index)
End Sub

Public Sub SetSingleKarte(Index As Int, Karte As clKarte)
   mKarten(Index)=Karte
End Sub

Public Sub GetTopItem(Index As Int) As Int
   Return mTop.Get(Index)
End Sub

Public Sub SetTopItem(Index As Int, Value As Int)
   mTop(Index)=Value
End Sub
Would those Get/Set Sub enable to get/set specific List-Items for mKarten and mTop?
 

LucaMs

Expert
Licensed User
I suspect that you can get what you want in another way.
The point is that I do not know exactly what you want to achieve.

The property must begin with "set" or "get" sensitive.

Writing "Set" and "Get" they are normal sub routines (they work, of course, but then you can't write statements like: MyClassObject.Name = ...)

I'm not very vigilant at this time (amazing but I'm developing :D).

Maybe you could use a Map.

B4X:
Private mKarten As Map
mKarten.Initialize

Sub getKarten As Map
  Return mKarten
end Sub


At this point, you could write:

B4X:
MyClassObject.Karten.Put(Index, MyObject)

MyObject = MyClassObject.Karten.Get(Index)


But you probably want to get something different, sorry :)
 
Upvote 0

James Chamblin

Active Member
Licensed User
AFAIK, property getters take no parameters, and setters only take one, so they can only be used on single items. To grab or set an item in a list, you probably need to do just as you are now. when using the functions, instead of

a = MyClass.mKarten 'get
MyClass.mKarten = a 'set

you will be using

a = MyClass.GetSingleKarte(1) 'get
MyClass.SetSingleKarte(1,a) 'set
 
Upvote 0

opus

Active Member
Licensed User
Thanks for the inputs. Yes, I can get or set specific list-items directly using the above posted get/set sub.
Problem solved.
 
Upvote 0
Top