Deals with various key topics in Xojo fundamentals

I am using an array of a user defined object, and am having problems in assigning elements (AddRow). It makes all rows the same object, as the final one assigned.

What does your loop look like? It sounds like you’re not creating new instances.

3 Likes

your code will be

dim d as new myclass
dim a() as myclass
for x as integer = 1 to 5
d.somevalue = someamount
a.addrow d
next

d.somevalue = someamount just changes a property of the same instance.
And you add the same instance over and over

You would change it to this:

dim d as myclass
dim a() as myclass
for x as integer = 1 to 5
d= new myclass  //this is the key
d.somevalue = someamount
a.addrow d
next
1 Like

Wow, Jeff that did it. Thank you so much. I had tried to work before with a New keyword, but I didn’t get the instance right like you showed me. Thanks for focusing right into my problems. Thanks and Kudos!