Passing an array from one window to another

How should I pass an array of FolderItems from one window to another?
Window2.arrayOfFolderitems = Window1.arrayOfFolderItems doesn’t appear to do it.


If you define the property as an array, it should work.
It works just like you’d dim a variable, but instead you type it into the inspector.

  1. Press cmd-alt-p to create a new property
  2. arfItems() as FolderItem
  3. Watch the magic!

You should be able to exchange the array as you’re trying to now :slight_smile:

Thanks Tim,

I’ve got a main window for the app and at some point a method of that window makes instances of another window, each of which has an array as folderitem property.

When the main window method instantiates a new window and tries to set NewWindow(i).arrayOfFolderItems = arrayOfFolderItems, the array in the newly spawned windows is empty. (Simple string variables appear to work.)

I couch this entry with the warning that I am not sure.

But you really cannot say in Xojo:

ArrayB = ArrayA and expect anything very substantial to have happened. You have not created a new array really. At best you have just created a second name for ArrayA.

If you want a second array to contain all the values that the first array has, you create the second array (say ArrayB) and then use a for loop or the equivalent to go through ArrayA and assign each value it has at every index to the equivalent index of ArrayB.

So unless someone with more confidence answers this question, I would try, after instantiating the new window, to make its array of folder items the same size as the array in the MainWIndow and then go through the array in theMainWindow and assign its values, element by element, to its equivalent array in the window just instantiated.

If all windows need to have access to the same folderitems, make the array a property of the APP and refer to it from anywhere as app.arrayOfFolderitems - no copying required - its ‘global’ in scope.
or add a module, make the array a public property of that

If each window can have an array and the contents can be different, then you must use the initialising loop that Robert suggests.

@Jeff Tullin that is what I ended up doing, thanks.
(@Robert Livingston, your suggestion is what occurred to me to try first but for some reason that didn’t work.)

I appreciate everyone’s advice – thanks.