A list of types

yo3ggx

Active Member
Licensed User
Longtime User
Hi,

I have the following example code:

B4X:
Sub Process_Globals
    Dim lstServers as list
    Type Srvdata(Name as String, Url as String)
End Sub


Dim srv as Srvdata
srv.Initialize
lstServers.Initialize
srv.Name = "Server1"
srv.Url = "http://a1.b.com"
lstServers.add(srv)

srv.Name = "Server2"
srv.Url = "http://a2.b.com"
lstServers.add(srv)

I end up with a list containing only the second Type for two times.

What I'm doing wrong?

Thank you,
Dan
 

Informatix

Expert
Licensed User
Longtime User
Hi,

I have the following example code:

B4X:
Sub Process_Globals
    Dim lstServers as list
    Type Srvdata(Name as String, Url as String)
End Sub


Dim srv as Srvdata
srv.Initialize
lstServers.Initialize
srv.Name = "Server1"
srv.Url = "http://a1.b.com"
lstServers.add(srv)

srv.Name = "Server2"
srv.Url = "http://a2.b.com"
lstServers.add(srv)

I end up with a list containing only the second Type for two times.

What I'm doing wrong?

Thank you,
Dan

Add:
B4X:
Dim srv as Srvdata
srv.Initialize
before the second assignement to create a second instance of the type SrvData. If you don't do that, all references to srv are pointing to the same object in memory.
 
Upvote 0
Top