Hello RichK,
Generally the code to present, dismiss, switch a dialog can be executed elsewhere. Essential is the component in context of which you invoke the methods PresentDialog(), SwitchToDialog() and DismissDialog(). Accordingly, the new dialog is presented in context of the specified component. It depends thus on what you expect in your application. Following examples demonstrate it:
1. Let's assume, there is a component A visible already on the screen.
2. Let's assume, there is a component B you want to present.
3. Let's assume, the component A contains a key handler and implement a method to execute when the handler is triggered.
4. If you want the component B to be presented in context of the same GUI component, the component A belongs already to, then invoke the method PresentDialog() or SwitchToDialog() in context of A's variable Owner. Consequently, the component B and A will be siblings within the same owner component:
Owner.PresentDialog( compB, ... )
5. If you want the component B to be presented nested within component A (embedded within A), then invoke the method in context of this (this represents the component A itself). Please note, that this keyword can be omitted. The so presented component B will appear nested within A:
PresentDialog( compB, ... )
6. If you want the component B to be presented within the application component itself (the root object of the application), then use GetRoot() to obtain access to the root object. The so presented component will appear at top level of the entire application:
GetRoot().PresentDialog( compB, ... )
To make your implementation more robust and prevent eventual race conditions, I would recommend to prefix the above code by an additional condition. For example, if component A was presented originally as dialog, present component B only, when A still acts as dialog:
if ( IsCurrentDialog())
GetRoot().PresentDialog( compB, ... )
... in turn, if A is just a regular component, but it is possible that it will be removed from the view tree, check whether it still belongs to the tree before presenting a new dialog:
if ( GetRoot())
GetRoot().PresentDialog( compB, ... )
See also:
The methods: PresentDialog, DismissDialog and SwitchToDialog
Understand the view tree and the Owner relationships (the Owner variable)
Access the root object (GetRoot())
Identify the active Dialogs and avoid race conditions
Does it help you further?
Best regards
Paul Banach