Create an object with parameter


First let me say that English is not my native language (sorry for wrong words or sentences!) and that I am new to Xojo.

My problem:
I want to store arrays of Strings (with items from a database) in a dynamic structure like the List class in Java. Since two-dimensional Arrays a too limited for my task, I want to create a List and a ListNode class; each ListNode object will have a property that holds my String array and a property that points to the next List object (plus some methods to work with the items). These ListNode objects will then be inserted in my list.

But there is one thing now with which I am stuck: When I create a class in Java, I can write a constructor with a parameter, so that I can set a property when creating an object, e.g.:
public ListNode(obj item) { property = item; }
Then I can simply create a new object with a certain property I give as parameter, e.g.:

ListNode listnode1 = new ListNode(item)

I know how to create a class and set a property, but how can I create (in a method) an instance of my class and set a property by parameter at the same time? (I could not find anything like a constructor like the one I know from Java…)

Thank you very much in advance!


Ah, sorry I did not find that myself!

Thank you very much!

I have got an additional question: Is there a concept of generics in Xojo, so that I can create a list class for an unspecified data type?

No. You would have to use ‘Auto’ or ‘Variant’, which lose compile time type safety.

Okay, thank you! :slight_smile: