Android Question create an array of types and every element gets set to the same value

tmf

Member
Licensed User
Longtime User
Type devv (deviceonoff As Boolean, devicekind As Int, devicefill As Int, devicepeaks As Int, devicemode As Int, devicechain As Int,devicecount As Int,brightness As Int,deviceflipx As Boolean,deviceflipy As Boolean,deviceenabled As Boolean,r(2) As Int,g(2) As Int,b(2) As Int,peakholds As Int,peakdecays As Int,fillholds As Int,filldecays As Int,devicevu As Boolean,length As Int)

Dim devices(6) As devv

when I set devices(0).devicekind = 1 all in the array get set the same

to verify it was not some odd code I would take out devicekind from type and just make

dim devicekind(6) as int and recode for that and all ok.... so its a mystery.

Richard.
 

tmf

Member
Licensed User
Longtime User
OK I have read it and studied it and do not get it....

I declare mine once in globals() and thats it....

Richard.
 
Upvote 0

tmf

Member
Licensed User
Longtime User
So when I used the TYPE declaration:
devices(0).dname = st is a reference (pointer to st)
and when I use
dname(0) = st its a value (not a pointer?)
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
this works without problems:

B4X:
Sub Process_Globals

Type devv(deviceonoff As Boolean, devicekind As Int)
Private devices(6) As devv

End Sub


B4X:
devices(0).Initialize
devices(1).Initialize
 
devices(0).devicekind = 1
 
Log(devices(0).devicekind)
Log(devices(1).devicekind)
Log(devices(2).devicekind)
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Sorry I am writing this from my cellphone,

Dim devices(6) as devv

For I to devices.length - 1
Dim device as Dev
Device.initialize(...)
Devices(I) = device
Next

In this way the other memory allocation will be different for every device you enter in the array.
 
Upvote 0
Top