Problem with complex types and structures

StevieDk

Member
Licensed User
Longtime User
Hello, i am not nooby on terms of object programing although i have started a few week with b4a, for android platforms.
I will try to explain what i think is a kind of bug that is getting me crazy.:BangHead:
I have defined a type such as:
Type SaeLine_ (descriptionField As String, _
idField As String, _
publicIdField As String, _
routesField As List )

i have another type defined as :
Type SaeRoute_(Descripcion As String, _
idLine As String, _
idRoute As String, _
PublicId As String, _
Tipo As String)

the type list is according to the documentation a type yhat accepts objects as members of the list ( something standard by the way).
I have defined two variables, one type Saeline_ and other type SaeRoute_

Well here is the problem, when i fill up the variable SaeLIne where the element routeFields have more than one SaeRoute element in the list, all the elements stored are all the same as the last one inserted. I have tryed diferent codes to check was not my code, bau allways the same. I have logged the element i am inserting, and check that every one is different, but the result is that when i "get" the elements inside the list, are all identical to the last inserted.
Can someone give me some light to this problem??
Thankyou
 

StevieDk

Member
Licensed User
Longtime User
More Info

I have tryied to serial the SaeRoute i mean i have link all members of Saeroute as one string just before adding the element to SaeLIne.rotesField and now it works, so i think is confirmed that i am infront of some kind of bug when a structure member is a list of another structure ( C nomenclature, sorry)

How can we check the code to see how to fix the problem? :sign0163:

Thank you

Stevie
 

StevieDk

Member
Licensed User
Longtime User
HI Thedesolatedsoul,
Thanks for your answer, but is exactly what i am doing, I have a global object created with the structure, i have in such a way because the structure is not filled in one go, but in several events. Once the structure is filled completely ( the global) i create a new one ( dim a new object) and load the new one with the global one, and add the new to the list. I am sure that until adding to the list everything is running correctly. Not only that, if i change my structure with a structured string, but a string at the end, everything works perfectly and the list is filling with no problem, but just if I change the type from a string to a data structure, all the elements in the list after adding for sure different ones, are exactly the same :BangHead:
I have my proyect working using the structured string, but is not very nice.
I you have the time to spend and you want, i can send the complete code.
thanks any way :)

Steve
 

thedesolatesoul

Expert
Licensed User
Longtime User
Once the structure is filled completely ( the global) i create a new one ( dim a new object) and load the new one with the global one, and add the new to the list.
If my guess is correct you are doing something like this at some point:
B4X:
newStructure = globalStructure

A type structure is usually assigned by reference, so essentially in memory, both of these variable are pointing to the same copy of data in memory (in memory there is only one).

To assign one custom type to another type you need to serialize it somehow. You will have to assign each primitive separately.
like
B4X:
newStructure.FirstInt = globalStructure.FirstInt

That is the theory.
In practice there are some shortcuts to copy objects (I dont use them, but some people do). Like here: http://www.b4x.com/forum/bugs-wishlist/25905-wish-copyobject-object-object.html#post149919

If you still are not sure you can upload your project or the relevant parts of your code, and if I or anyone else on the forum has time, someone will look at it.
 
Top