Hot to make Array persistent?

Hello

I’m trying to make an Array persistent. Initially I wanted to create a property of type Array but that seems not to be allowed (error message). I’m aware I could create a Global for a persistent Array but this is not “proper” coding.

Do you have any idea how I could solve this? It does not even be of type Array but something that allows me to store a list of unknown amount of values, that I can make persistent and read/change at runtime of my Desktop App.

You can make a property of type array.

Just type () on the end of the property name.

Excellent, not only very quick but also very useful!

For completeness if someone runs into same problem:

  1. Create a Class myClass
  2. Create a “Shared Propery”* inside myClass:
    • Name: MyArrayb[/b]
    • Scope: Public
  3. Access the shared property this way from anywhere in your code:

[code]MyClass.myArray = Array(“a”,“b”,“c”)

MessageBox ( MyClass.myArray(1) )[/code]

  • Why Shared Property: If it’s just a property you need to make an instance of myClass to be able to access the property MyArray. This would work as well but the property access would only work where you instanced the Class MyClass. That way it wouldn’t be persistent (if you make another instance of MyClass somewhere else in your code would not deliver previously set values of MyArray by another instance).

@Christian Schmitz : Please correct me if I wrote something wrong and thanks for your appreciated help!

MyClass.myArray is just an array, so you can access/append from everywhere

e.g.

[code]MyClass.myArray.append “123”

dim s as string = MyClass.myArray(0)[/code]

Or you add a Module to your Project and add a Property there…

Static myArray() as string

http://documentation.xojo.com/api/language/static.html

Thanks all!

@Christian Schmitz : Not sure with your additional answer if you mean w/o making a shared property or an instance of it but I try it out. -> MyArray was not found as simple propery, so I keep it as shared property

@Emile Schwarz : Agree but with Module I loose the advantage on further instancing

@Michel Bujardet : It can’t be startic… I need to change it at runtime

You are confusing with constant.

A Static variable keeps it’s value between calls to a method or event handler, but of course, you can modify it.

You’re right, sorry! I will test it out for my needs…