Closing forms that are "realized" but not shown

Date:30 April 2002
Product/Release:Visual LANSA
Abstract:Closing a form that is realized but not shown does not end the instance of the form
Submitted By:LANSA Technical Support
Last Review:November 2010

It is possible to close down your Visual LANSA application and still have the x_run listed and seemingly still running when you look in the Task Managers Processes list. The issue generally can be attributed to the existence of realized forms that are have not been shown. A typical situation that might cause this scenario is if your main form invoked a method in a child form but never showed the child form. Visual LANSA will continue to run its message loop while it believes that there are realized forms still awaiting messages. It does not make a distinction between visible and invisible forms; just forms that are realized. So if an application's main form closes and there are other forms still realized, the main form will disappear from the desktop but the application will continue to run.

For example, take a situation where a form automatically realizes each secondary form as the form instance is created and stores the realized form in a collection. When the main form shows and then closes a secondary form, the default Visual LANSA behaviour is to unrealize the closed form. This is why the application shuts down when the main form is closed. If a secondary form is never shown (it just sits in the collection in a realized state), the application will not shutdown because Visual LANSA thinks that there are realized forms still needing a message loop.

There are a number of solutions to avoid this problem:

  1. Don't keep forms realized all the time. Only realise them as you show them.
  2. Set the FormStyle of secondary forms to be FormStyle(NormalChild) and just before invoking the Realize method set the secondary form's FormOwner property to be the application's main form (like Set ... FormOwner(#Com_Owner) ). This will mean that the secondary forms will automatically close and unrealize when the main form is closed.