Destroying Controls


When an application in ARWEN is closed the library destroys all the controls that were created and (hopefully) release all allocated memory. However, there may be occasions when the user would like to destroy a control while the application is still running. An example of this could be a set of text labels along the axes of a graph. If the boundaries of the graph are altered so that the number of labels is different then the labels should really all be destroyed and then recreated. To destroy a control or Menu or MenuItem simply use:

        procedure destroy(integer id)

If the control is a Menu then ARWEN will destroy all attached MenuItems but will only unattach (sub) Menus before destroying the Menu itself. Please note that after ARWEN destroys the control via the API it simply marks the id slot as vacant and will recycle it at the next available opportunity. Therefore, beware of how the id of the original control is accessed in other parts of the program since it's type could be altered which would cause much confusion. Perhaps a good idea is to limit recreated controls to static types. Another problem with destroying & recreating (non-static) controls is where you must have a handler associated with them. This means that you must invoke setHandler() after recreating the control and since handler routines are generally at the end of the source code there are opportunities for frustration due to Euphoria's declare-before-use philosophy. The solution is declare an integer variable at the top of the program that will eventually be assigned the routine id of the handler and use that integer variable in setHandler() anywhere you like in the program.