Hi!
I need some help with getting a reference to the table within On Close statement of that said table.
I have a simple script: GUI with "Open" button, that opens a data table, and a combo box with list of tables.
I also keep track of the tables in an associative array with table names as keys and table references as values.
I have a couple of legacy namespaces that I have to maintain in this script. In order to remove table from the the combo box I use this Eval(Eval Expr(Expr())) trick in OnClose statement. However, this trick doesn't work with removing table from Associative Array.
There is another trick with Function({this}, _dt = ((this << Child) << Get Data Table)). It works correctly with getting the reference to data table, but stops working when I place it within Eval(Eval Expr(Expr()))).
I tried to get the reference to the table separately, but looks like I don't know how Function({this}, <script>) works. How do I assign a result of this function to a variable?
Anyways, here's the latest iteration of my script, please help me tweak it to make it work.
Eventually, I will need to handle data table manual name changes somehow and reflect it in the combo box.
Names Default To Here( 1 );
data = New Namespace(
"DataTables"
);
gui = New Namespace(
"GUI"
);
data:tablesListAA = [=> ];
gui:guiWindow = Expr(
Border Box( Left( 10 ), Right( 10 ), Top( 10 ), Bottom( 10 ), Sides( 15 ),
V List Box(
gui:cb = Combo Box(
{},
selection = gui:cb << GetSelected();
Print( "Selected: " || selection );
Current Data Table( data:tablesListAA[selection] );
Print( "Current Data Table: " || (Current Data Table() << Get Name) );
),
Button Box( "Add Table",
filePath = Pick File(
"Select JMP File",
"$SAMPLE_DATA",
{"JMP Files|jmp;jsl;jrn", "All Files|*"},
1,
0,
"newJmpFile.jmp"
);
dt = Open( filePath );
Eval(
Eval Expr(
dt << On Close(
getTable = Function( {this},
_table = ((this << Child) << Get Data Table);
Return(_table);
);
_table = getTable(this);
Local( {data = Namespace( Expr( data << Get Name ) ), gui = Namespace( Expr( gui << Get Name ) ), _table = Expr(_table)},
Try(
_tableName = _table << Get Name;
Print("Trying to remove: "||_tableName);
Remove From( data:tablesListAA, _tableName );
gui:cb << Set Items( data:tablesListAA << Get Keys );
)
)
)
)
);
dtName = dt << Get Name();
Insert Into( data:tablesListAA, dtName, dt );
gui:cb << Set Items( data:tablesListAA << Get Keys );
)
)
)
);
nw = New Window( "Test table selection", gui:guiWindow );