In this section, you extend the test windows to see a couple of different ways persistent procedures can communicate with one another.

To add a fill-in field to the main window to locate and manipulate one of the Order windows:

(You just add code to hide or view it alternately, just to show that you can access it.)

  1. Open h-OrderWin.w and add this statement to the main block (after RUN enable_UI.) to save off the Order Number in the procedure’s PRIVATE-DATA attribute:
    ASSIGN THIS-PROCEDURE:PRIVATE-DATA = STRING(OrderNum).
  2. Open h-CustOrderWin6.w and add a fill-in to the window. Call it iOrderWin and give it the label Show/Hide Order.
  3. Define this LEAVE trigger for the new fill-in:
    DO:
      DEFINE VARIABLE hProc AS HANDLE NO-UNDO.
      DEFINE VARIABLE hWin AS HANDLE NO-UNDO.
      hProc = SESSION:FIRST-PROCEDURE.
      DO WHILE VALID-HANDLE(hProc):
        IF hProc:FILE-NAME = "h-OrderWin.w" AND
          hProc:PRIVATE-DATA = iOrderWin:SCREEN-VALUE THEN
          DO:
            hWin = hProc:CURRENT-WINDOW.
            hWin:HIDDEN = IF hWin:HIDDEN THEN NO ELSE YES.
            LEAVE.
          END.
        hProc = hProc:NEXT-SIBLING.
      END.
    END.

    This trigger block walks through the persistent procedure list managed through the SESSION handle. When it comes to an instance of h-OrderWin.w whose PRIVATE-DATA attribute matches the value in the fill-in, it saves off its CURRENT-WINDOW attribute, which is the handle of the procedure’s window. If the window is currently hidden it is viewed, and vice versa.

  4. Save the changes and test them out:
    1. Run h-CustOrderWin6.w.
    2. Click the Order Detail button for a few different Orders.
    3. Enter one of the Order numbers into the Save/Hide Order fill-in and tab out of it. The window displaying that Order should disappear, or reappear if it is already hidden.

This is a simple example of how to use the SESSION procedure list to locate a procedure you are interested in, and then either manipulate that procedure object or make a request of it in some way.

The next example goes in the opposite direction. Rather than locating one of the Order windows from the main window, you add code to the Order window procedure to request the handle of another procedure from the main window. It then uses that handle to reposition the other Order window. A new internal procedure in the main window provides an interface the Order window can use to get the handle it needs.