Jump to content

Removing an element from a global array affects other elements in the array


Recommended Posts

The basic setup for my program is as follows:

I have a Global Array of "Device" objects (each of which is actually an object of a type that descends from Device). Each object has a bunch of different pieces of information, including a table of data.

I'm having an interesting problem with removing a device from this global array. Once I do so (inside of a VI that reads the Global variable, calls the remove element array function on it with the relevant index, and sends the output back to the global variable, setting it), the data table of each device proceeding the removed element in the array gets blanked out. As in, set to the default value - the table dimension sizes are still the same, the array is not empty, just at its default value. Curiously enough, the other pieces of information stored as the private data for each object (everything besides the data table) are still intact post-removal. I have an idea of what might be causing this behind the scenes (shifted pointers in the removal process get messed up or something), but I have no idea how I can fix it.

My question is, of course, how do I remove an element but ensure that all proceeding elements have all their data intact?

Any help is greatly appreciated!

Link to comment

Hmmmm. Upon further inspection (really should have done this before I posted). The data gets blanked out only when a certain type of device is removed. This device type, we'll call it "DS", has a table that should be 3x3. the other device type I've been trying it with, we'll call it "NT", has a table that should be 3x12. I thought this would be irrelevant because both tables are inside separate private data clusters for their respective classes. No VIs are being called on the devices themselves in this process, only the remove element function is called on the global array of devices.

Link to comment

Wow I feel pretty stupid. My issue was that I had two different VIs working with the global and one was using shift registers. In one VI I am able to edit the data and in the other I am able to add and remove devices. In the add/remove device VI I was using a shift register to store any changes until a Save button was pressed. Oftentimes I would make changes to the data in the editing VI while this was running, then go and delete a device and Save. This would take the value that was being passed along the shift register (and not the data values that had recently been updated into the global device array) and store it into the global device array. The effect was the device was removed, but none of the updates that took place in the editing VI were actually saved.

My solution was to just add a boolean to the global variable that can be used to detect when a change was made in the editing VI.

Sorry for wasting anyone's time!

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.