The h-CustOrderWin6.w procedure runs a separate window called h-OrderWin.w to display details from the current Order. You can run this Order window multiple times.

To see how you can use PUBLISH and SUBSCRIBE statements to extend the communication between these procedures:

  1. Open h-OrderWin.w and save it as h-OrderWin1b.w.
  2. In h-OrderWin1b.w define this internal procedure called ShipDateChange:
    /*---------------------------------------------------------------------
      Procedure ShipDateChange:
      Purpose: receives the event of the same name to update the
               ShipDate field display when the field value changes.
      Parameters: Order Number and new ShipDate SCREEN-VALUE.
      Notes: ShipDateChange is PUBLISHed by h-CustOrderWin6.w
    ---------------------------------------------------------------------*/
    DEFINE INPUT PARAMETER iOrderNum AS INTEGER NO-UNDO.
    DEFINE INPUT PARAMETER cShipDate AS CHARACTER NO-UNDO.
    
    IF STRING(iOrderNum) = Order.OrderNum:SCREEN-VALUE IN FRAME OrderFrame
    THEN
    DO:
      Order.ShipDate:SCREEN-VALUE IN FRAME OrderFrame = cShipDate.
      shipDate:BGCOLOR = dateColor(PromiseDate, DATE
        (ShipDate:SCREEN-VALUE)).
    END.
    
    END PROCEDURE.

    This code responds to an event published by the main window whenever the value of the ShipDate field changes. It receives both the Order Number and the new ShipDate as INPUT parameters. If the Order Number matches the one displayed by this instance of OrderWin, then the displayed ShipDate is changed to the value passed in, and the dateColor procedure is run to flag it with a new background color if its value requires this warning signal.

  3. Add this SUBSCRIBE statement to the main block of h-OrderWin1b.w:
    ASSIGN THIS-PROCEDURE:PRIVATE-DATA = STRING(OrderNum)
      hSource = SOURCE-PROCEDURE
      shipDate:BGCOLOR = dateColor(PromiseDate, ShipDate).
    SUBSCRIBE TO "ShipDateChange" IN SOURCE-PROCEDURE.
    IF NOT THIS-PROCEDURE:PERSISTENT THEN
      WAIT-FOR CLOSE OF THIS-PROCEDURE.

    This sets up every running instance of h-OrderWin.w to receive the ShipDateChange event when the SOURCE-PROCEDURE h-CustOrderWin publishes it. There might be multiple instances of OrderWin that have subscribed to the event. Under other circumstances, there could just as easily be multiple, completely different versions of the procedure ShipDateChange in multiple different procedure files that do different things with the changed ShipDate information. The publisher has no reason to know or care.

  4. In h-CustOrderWin6.w, go into the property sheet for the OrderBrowse and enable the ShipDate column.
  5. Define this LEAVE trigger for the ShipDate field:
    DO:
      IF Order.ShipDate NE DATE(Order.ShipDate:SCREEN-VALUE IN BROWSE
        OrderBrowse)
      THEN PUBLISH "ShipDateChange"
        (INPUT Order.OrderNum, INPUT Order.ShipDate:SCREEN-VALUE).
    END.

    If the field value changes, the published event notifies all subscribers.

  6. Run the main window and click the Order Details button several times for different Orders to bring up multiple instances of OrderWin.
  7. Modify the ShipDate for one of those Orders, then tab out of the field.

    The corresponding OrderWin instance for that Order shows the new ShipDate, possibly with a different color, depending on the value of ShipDate, as this sequence shows:

    1. Run h-CustOrderWin6.w and click the Order Detail button for several Orders:

      One of those orders shows that there is no ShipDate:

    2. Enter a ShipDate for the Order, then tab out of the field:

      Now the Order Detail window for that Order shows the new date: