Don't understand Lists and...

BlitzMax Forums/BlitzMax Beginners Area/Don't understand Lists and...

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

A standard situation: You define a user Type and create a List to manage the data content. But what are the relationships between the List and the Type variable furtherly ?

My first idea was: Furtherly you have two divided data contents, one in the List and one in the Type variable, each going its own way.

But if you change the Type variable after adding it to the List, the List data also is changed. If you on the other hand change the Lists content, the Type Variables content is also changed.

So are they two representation of a single data block somewhere in the RAM ? Two instances of a
hidden third object ?

But if you then set the Type variable to NULL, the Lists content isn't influenced at all (in other words: it's not ALSO setted to Null). Same rules for the Type variable if you delete the Lists entry. How comes that ? Does anyone know, what concepts lie under this behaviour ?

Strict

Graphics 800, 600,0
SetClsColor 0,0,0'133, 133 ,133

' a Type....
Type test
    Field ID:String =""
	Field a:Int
End Type

'...and a List to hold the data of the Type
Global allTests:TList =CreateList()

' make one Type variable and add it to the List
' to investigate furtherly their relationships
Local tmpTest:test =New Test
tmpTest.ID ="First"
tmpTest.a =111
ListAddLast allTests, tmpTest

DebugLog "-------------------------------------"
DebugLog "the Types variable content:"
DebugLog tmpTest.ID
DebugLog tmpTest.a
DebugLog ""
DebugLog "the Lists data content:"
For Local curTest:test =EachIn allTests
  DebugLog curTest.ID
  DebugLog curTest.a
Next

DebugLog "-------------------------------------"
DebugLog "set Types a to 555:"
tmpTest.a =555
DebugLog tmpTest.a
DebugLog "the effect for the Lists  data content : "
For Local curTest:test =EachIn allTests
  DebugLog curTest.ID
  DebugLog curTest.a
Next

DebugLog "-------------------------------------"
DebugLog "Reversed way: set the Lists data content to 777 :"
For Local curTest:test =EachIn allTests
  curTest.a =777
  DebugLog curTest.ID
  DebugLog curTest.a
Next
DebugLog "the effect for the Type variable: "
DebugLog tmpTest.a

'Rem
DebugLog "-------------------------------------"
DebugLog "Now delete the Type variable..."
tmpTest =Null
' this now would give an error message "Null object" :
'DebugLog tmpTest.a
DebugLog "What happens to the List (nothing !) : "
For Local curTest:test =EachIn allTests
  DebugLog curTest.ID
  DebugLog curTest.a
Next
DebugLog "-------------------------------------"
'EndRem

Rem ' alternatively....
DebugLog "-------------------------------------"
DebugLog "Now delete the List content..."
For Local curTest:test =EachIn allTests
  ListRemove allTests, curTest  
Next
allTests =Null

DebugLog "What happens to the Type variable (nothing !) : "
DebugLog tmpTest.a
DebugLog "-------------------------------------"
EndRem