Hi all,
Background: I am currently writing an add-in where I am needing to create a temporary data table to hold some data points that are then being fed into Graph Builder. When the user closes the Graph Builder, I want the temporary data to go away. Easy enough, if I save the Graph Builder call to a variable, I can add an << On Close() to also close the temporary data.
However, strange things happen if my user wants to run the add-in twice against two different inputs, thus creating two temporary data tables and two Graph Builders. Now in this case, closing one of the Graph Builders may close the wrong temporary table (bringing down the other Graph Builder with it).
I imagine there must be a simple solution to this. I think the solution should be with Namespaces, but I can't figure out how to keep everything linked together! It seems that each time I make a new Namespace, the "ns" gets overwritten. The conundrum I have is in figuring out how to keep each separate instance of the add-in using its own "ns" value, and in such a way that I can feed the correct "ns" value into each of the several "On Close" codes that end up getting created.
Here's a simplified version of what I'm trying to do. The idea would be that if I run this, and then click the "Make Another One" button one or more times, and then dismiss one of the Graph Builders, the other one(s) will stay intact - without any concern about which Graph Builder I choose to dismiss first.
Names Default to Here(1);
MyFunction = Function({},
ns = New Namespace();
ns:dt = New Table("Test Table",
<< New Column("Random X", << Formula(Random Normal())),
<< New Column("Random Y", << Formula(Random Normal())),
<< Add Rows(10),
invisible
);
ns:gb = New Window("Test Output",
Button Box("Make Another One",MyFunction()),
Graph Builder(
Show Control Panel( 0 ),
Show Legend( 0 ),
Variables( X( :Random X ), Y( :Random Y ) ),
Elements( Points( X, Y, Legend( 4 ) ) )
);
);
ns:gb << On Close(Try(Close(ns:dt, No Save)); ns << Delete);
);
MyFunction();
Looking for wisdom: What should I try next?