按钮框中的局部函数变量你好,
我正在寻找一种方法,以便在函数内部创建按钮框时访问局部变量。我看到这里有一个帖子,建议的解决方案是将变量分配给窗口命名空间。但是,我认为这不适用于我需要构建的报表,因为它们在同一个窗口中有多个可重用的组件。
在我的示例中,我只是尝试打印链表的值,但我希望在最终脚本中做更多的事情(在测试/使用全局变量作弊时,所有功能都可用)。
// 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();