按鈕框中的局部函數變數你好,
我正在尋找一種方法,以便在函數內部建立按鈕框時存取局部變數。我看到這裡有一個帖子,建議的解決方案是將變數分配給視窗命名空間。但是,我認為這不適用於我需要建立的報表,因為它們在同一個視窗中有多個可重複使用的元件。
在我的範例中,我只是嘗試列印鍊錶的值,但我希望在最終腳本中做更多的事情(在測試/使用全域變數作弊時,所有功能都可用)。
// General Component - List Box
make_a_list_box = Function( {list_in},
{Default Local},
l_box = List Box( list_in );
Return( l_box );
);
// General Component - Button linked to a specific list box
linked_button_box = Function( {button_name, target_list_box},
{Default Local},
b_box = Button Box( button_name, Print( target_list_box << Get Items ) ); // Name Unresolved: target_list_box
Return( b_box );
);
// Basic Module - Expect multiple in a shared window
report_module = Function( {list_in, button_name},
{Default Local},
report_list = make_a_list_box( list_in );
report_button = linked_button_box( button_name, report_list );
report = H List Box( report_list, report_button );
Print( report_list << Get Items );
Return( report );
);
// Example Window using multiple modules
New Window( "Test",
V List Box(
report_module( {"A", "B", "C"}, "Letter" ),
report_module( {"1", "2", "3"}, "Number" )
)
);
自動化和腳本編寫回覆:按鈕框中的局部函數變數您可以使用上下文框
Names Default To Here(1);
make_a_list_box = Function({list_in},
{Default Local},
l_box = List Box(list_in);
Return(l_box);
);
// General Component - Button linked to a specific list box
linked_button_box = Function({button_name, target_list_box},
{Default Local},
b_box = Context Box(
box:target_list_box = target_list_box,
Button Box(button_name,
Print(box:target_list_box << Get Items)
)
);
Return(b_box);
);
report_module = Function({list_in, button_name},
{Default Local},
report_list = make_a_list_box(list_in);
report_button = linked_button_box(button_name, report_list);
report = H List Box(report_list, report_button);
Print(report_list << Get Items);
Return(report);
);
nw = New Window("Test",
V List Box(
report_module({"A", "B", "C"}, "Letter"),
report_module({"1", "2", "3"}, "Number")
)
);
Write();