Tips_tutorials   >   Studio104   >   Headed List Subwindow

Headed List Subwindow

The headed list object is one of my favorite list objects in Omnis Studio. In this section we will create a window which has a headed list object. The window will be generic in design, allowing it to be used as a subwindow to present different data lists.

List Object vs. List Variable

One thing we need to clarify when talking about lists is the difference between a list object and a list variable.

  1. List Variable - A variable with the variable type set to List. The list variable has columns and rows and holds data. The list variable does not present the data to the runtime user. In a window class you normally use an instance variable for any lists you want to display in a list object. For clarity, I normally refer to a list variable as a data list.
  2. List Object - A window field object that is used to display the contents of a list variable to the user. Omnis Studio has numerous list objects: kCheckList, kComplexGrid, kDataGrid, kDroplist, kHeadedListBox, kStringGrid

Create Headed List Window

To create the headed list window class:

  1. F2 Browser > select Contacts library > click New Class > click Window.
  2. Name the window class, wHeadedList.
  3. Right-click on the window class in the F2 Browser and select Methods... in the context menu.
  4. Add the following instance variables in the Variables pane:

    irDataList - Type - Item Reference - used to point the a list variable in the parent window
    irListObj - Type Item Reference - points to the headed list object in this window
    irParent - Type Item Reference - points to the parent window instance
  5. Add a $setParentRef method to the wHeadedList class methods.
  6. Add the parameter, pfrParent - Type - Field Reference to the $setParentRef method.
  7. Add the following code to the $setParentRef method.

    ; Register this window's parent for sending event messages.
    Set reference irParent to pfrParent.$ref
    Quit method kTrue

    Later in this tutorial when the wHeadedList is instantiated as a subwindow, the $setParentRef method will be used by the parent window to register itself as the parent of the child subwindow.
  8. Add a $:ListObjRef property method to the wHeadedList class methods.
  9. Add the following code to the $:ListObjRef method.

    ; Return a reference to the list object.
    Quit method irListObj

  10. Add a $setDataListRef property method to the wHeadedList class methods.
  11. Add the following code to the $setDataListRef method.

    ; Set ivar reference to the data list field.
    Set reference irDataList to pfDataList.$ref

  12. Press F3 to jump from the method editor to the window class editor of the wHeadedList window class.
  13. Press F3 again to open the Component Store palette window.
  14. Drag and drop the Headed List object from the Component Store to the wHeadedList window class.
  15. With the headed list field object selected press F6 to go to the field's properties.
  16. Set the headed field list properties as follows:

    General tab
    $name - HeadedListObj
    $dataname - irDataList
    $top - 20
    $left - 20

    Appearance tab
    $designcolumns - 1
  17. Double-click the headed list object to go to the object's methods.
  18. Add a $construct method to the headed list object and enter the following code in the method:

    ; Set ivar reference to the field.
    Set reference irListObj to $cfield

    ; Expand the field to fill the window class.
    Do $cfield.$edgefloat.$assign(kEFposnClient)

    The $construct window class method code will run when the window is instantiated, just prior to it becoming visible in the display.
  19. Select the $event method of the headed list object and replace the existing code with the following code in the method:

    ; Test to make sure the parent has a recipient method.
    If irParent.$event_HeadedListObj.$cando
       ; Forward the event message to the parent.
       Do irParent.$event_HeadedListObj
    End If

    All headed list events will be forwarded to the registered parent, provided that the parent window class has an $event_HeadedListObj method.