SubPanels are a great way to break a complicated UI down into smaller components with their own areas of responsibility. DQMH modules are particularly suited to this task as they already have well-defined methods for getting data in and out, and they make creating multiple copies of a module easy as well
The steps required to insert a DQMH module’s front panel into a SubPanel control are straightforward:
- Add a Request and Wait for Reply event to return a reference to the Main.VI
- Pass this reference into the SubPanel’s Insert VI property
The simplest way to demonstrate this is using the API Test VI generated by the DQMH scripting tools
Add a Request and Wait for Reply event
In order to insert the front panel of the module’s Main.vi into a subpanel, we need a reference to the Main.vi
Create a new event from the DQMH menu, and set the type of event to Request and Wait for Reply. The returned datatype will be a VI Reference
Inside the module, just drop in a VI Server Reference constant and wire it into the event response. By default this will be a This VI reference, which is exactly what we want
Pass the reference into the Insert VI property
Next, add a SubPanel control to the front panel of your module’s API Tester. Take the VI Reference returned by your new event and wire it into the SubPanel’s Insert VI property
Now run the API Tester and try the new VI Reference event. It turns out there is a surprise 3rd step in the process –
- Get error 1144 because the Main.VI is already open
At first this appears to be a major problem, because of course the module’s Main VI is open, we’ve just started the module. There doesn’t seem to be an obvious way around having the module open when you need it to be running so you can request its VI Reference.
Luckily it turns out that the problem is not so much that the VI is open and running, but that its front panel is ‘open’ – even though it might be hidden
This is easily solved by forcing the Front Panel to be closed before inserting it – just add an Invoke Node to call the FrontPanel.Close method before passing the reference to the Insert VI property.
You don’t need to worry about the VI being unloaded from memory, because the reference to it is retained in the SubPanel1 – just remember to hang onto the reference somewhere else if you unload it from the panel later. This video by Christina Rogers (@eyesonvis) is a great explanation of what does and doesn’t keep a VI in memory
One other thing worth mentioning is that the Hide Panel event will behave differently while the module is inside a SubPanel. Instead of hiding the module’s Main VI, it will hide the front panel of the VI containing the SubPanel control. When designing your module, it’s worth giving some thought to how it should handle the Show Panel and Hide Panel events while inside a SubPanel
Finally, this method puts the responsibility for managing the subpanel insertion on the calling code, which means there is more boilerplate code outside of the DQMH module for you to implement. You can get around this by making the DQMH module itself manage the subpanel – this is particularly useful if you have several clones of the module
One thought on “How to Easily Insert a DQMH Module into a SubPanel”
Comments are closed.