strange update of DatabaseRecord

I fill a ListBox with a RecordSet.
I include the DatabaseRecord as a rowTag for each line.
dim dbr as new DatabaseRecord
for fld as integer = 0 to rs.FieldCount-1
dbr.Column(fldName(fld)) = rs.IdxField(fld+1).StringValue
next
Listbox1.RowTag(Listbox1.lastindex) = dbr
I verify dbr.column(ba_type) which = “2”

I select a line (row)
and change listbox1.Cell(row,13) in that row from stringvalue “2” to “0”

sub update(row)
dim dbr as DatabaseRecord
dim dbr2 as DatabaseRecord
dbr = Listbox1.RowTag(row)
dbr2=dbr
dbr.column(ba_type) = listbox1.Cell(row,13)

I verify the values:
dbr.column(ba_type) = “0”
dbr2.column(ba_type) should be “2”
but it is “0”
This means that an update of dbr, updates also dbr2
Am I dreaming?

Nope
dbr and dbr2 are referring to the same object and therefore the same data

This is like saying “my house” and “my home” - they are two names for the same place so when you change the couch in one the couch in the other changes as well :slight_smile:

Object assignment does not work like assignment of say Integer or Double etc…

Objects are basically pointers…

DBR points to the storage location for the first database record
DBR2 points to the storage location for the 2nd database record

but when you say DBR2=DBR, you are telling XOJO that they now BOTH point to the first record storage location,

Strange
I understand that
a = b
c = a
so
c = b
but if
c = “Roland”
b = c
instr(c,3,1)=“n”
then c = “Ronand”
but b should be “Roland”

[quote=239381:@roland brouwers]Strange
I understand that
a = b
c = a
so
c = b
but if
c = “Roland”
b = c
instr(c,3,1)=“n”
then c = “Ronand”
but b should be “Roland”[/quote]

and you would be correct… but this example uses scalar variables not objects

So
when I verify the rowTag
I see that this one is also changed.
Right?

My Question:
How can I buffer dbr into something else AAA
change dbr
do something with it
and
get the original value back like
dbr = AAA

This is a fundamental difference to understand
One is a “reference type” and the other a “value type”

integers, strings etc are value types - when you assign a = b it copies the value
ie i = 6
j = i
j now directly holds 6

reference types “refer to” things - they are not directly the value of the item
ie/
dbr =
dbr2 = dbr // this puts into dbr2
and now dbr2 “refers to” the exact same location in memory where dbr refers to

this is why I used the analogy of “my house” and “my home”
“my house” is a reference
“my home” is another
but this is just two names for the same place (where you live)

so if you change the house color both “my house.color” and “my home.color” change

[quote=239384:@roland brouwers]So
My Question:
How can I buffer dbr into something else AAA
change dbr
do something with it
and
get the original value back like
dbr = AAA[/quote]
copy the DATA and hold on to it separately

I was hoping for a more simple way (less code)
But that is what live is about sometimes
Using more words to be not misunderstood, where more is like ‘not to much but enough’

I thank you guys for this extensive answer
I learned something today.