Omnis Technical Note TNGI0018 Aptil 2007

Using $dataname in Subwindow fields

For Omnis Studio 3 or after.
By Andreas Pfeiffer

Have you ever wondered why a subwindow field has the $dataname property?

A subwindow should normally be designed in a way that it will work independently from its environment. If you want to use it in the context of another window you have to implement a messaging interface - something that is quite easy to do.

In some cases, however, you may only want to replace a single field. So you want to build a field that has implemented certain functions already. You may also have wanted to allow inheritance on the field level. You can achieve this using a subwindow.

Let's assume you want to build a headed list box that has functions for sorting and printing. But you also want this field available globally in your application, that is, a field like an Omnis component that you can simply drag and drop onto your window, enter the $dataname - and it should work.

To achieve this create a new window and name it something like 'wHeadedListBox'. Drag a headed list box onto this window and implement your functions for sorting and so on. You should set the $edgefloat property of the list box to kEfPosnClient. This ensures that the list box expands to fit the subwindow field. Leave the $dataname of the headed list box empty.

In the $construct method of the window class, enter the following code; this ensures that the list box uses the $dataname of the subwindow field:

Do $cinst.$objs.ListBox.$dataname.$assign($cinst.$dataname)

'ListBox' in this case is the name of the headed list box in your subwindow. $cinst references the instance of the subwindow so it can access the property of the subwindow field.

When you now assign the property $issubwindow to your window class wHeadedListBox, it will appear in the Subwindow category in the Component Store and you'll be able to drag it onto another window as a subwindow field.

Omnis desktop

When you have created another window and added the listbox subwindow field, you have to assign the name of your data list to the $dataname property of the subwindow field.

Omnis desktop