How to modify an object in an array (XojoNotesWeb example)

I watched Paul Lefebvre’s webinar where he built the XojoNotesWeb app which is also distributed with Xojo.
After the video and after closely looking at the application itself I still don’t understand something (consider that I am new to Xojo and not so familiar with OOP):

All tasks are saved in an array at session level.
Existing tasks can be modified by double clicking on the task (displayed in list box). A web dialog opens, the task object’s properties are shown and can be changed.
Once done, one hits the “save” button … at this point the properties are copied back to the object’s property (which exists on web dialog level (it is called “CurrentNote”)), the web dialog is closed and the listbox is refreshed by fetching all objects from the notes array at session level
–> And this is the magic to me!
–> How did the changed note get from “CurrentNote” property into the Session array?

In my opinion there are two objects at a certain point. One is the original one, in the Sesseion Array and the second one is the modified one.
My approach would have been to search somehow the correct object in the array and replace it with the changed one.

Since the application works find, I know that my opinion is wrong :slight_smile:
But I don’t understand why.

I hope that 1) I could express my doubts and 2) someone can explain it in a simple way.


mmh, went on with my research …
When saving an object to the RowTagAt of a list box, does it save a pointer to that object and not the object itself?
I mean, If I have several objects saved to a property (array) and I populate a list box by adding all objects from the array to the RowTag, in that case each RowTag cotains a pointer, is that correct?

An object created with NEW (for example) is “the instance” of the object… and references are to a pointer of the object

Dim obj1 as new myObject
Dim obj2 as myObject = obj1
Dim objArray(3) as myObject

in this nonsensical example. There is only ONE instance of “myObject”… and the is the one created as obj1
Obj2 is a copy of the pointer to Obj1, so any changes to Obj2 will be seen in Obj1 (since they are the same instance)
ObjArray has 3 items. 0 and 1 are NIL, and (3) also points to the same as Obj1

This can be quite confusing until you get your head wrapped around it, but one you do… it can be quite handy

Common Mistake

Dim temp as new myObject
dim objArray() as myObject
for i=1 to 10
   objArray.append temp
next i

All 10 items in the array point to the SAME object, so all will have the value of 10, since it was the last value assigned

the “right” way would be

dim temp as myObject
dim objArray() as myObject
for i=1 to 10
  temp=new myObject // create a unique instance
   objArray.append temp
next i

if you assign a object with = then it is the same and not a copy.
if you give a object a method it is usually byref by reference.
if you see a .Clone method it create a new object and copy it properties and return this new object reference.

other spelling to the example above

Dim objArray(10) As Class1 For i As Integer = objArray.FirstRowIndex To objArray.LastRowIndex objArray(i) = New Class1 objArray(i).Value = i Next

From the array doc page:

Perhaps these other OOP topics might help clarify things for you:

Thanks a lot, to all three of you!
Great help!

@Paul, I understand now that you did not use magic in your XojoNotesWeb app but just Xojo :slight_smile: