Progress
Programming
Handbook


Named Widget Pools

Progress supports two types of named widget pools: persistent and nonpersistent. A persistent widget pool remains allocated until it is explicitly deleted or the session ends. A nonpersistent widget pool remains allocated until it is explicitly deleted or the procedure block that creates it goes out of scope. When execution of a procedure or trigger ends or goes out of scope, Progress automatically deletes any nonpersistent widget pool defined in that routine.

NOTE: A persistent procedure goes out of scope only when it is explicitly deleted. Thus, non-persistent widget pools created in it can persist as long as the procedure persists.

When you create a dynamic widget, you can assign it to a named pool by using the IN WIDGET–POOL option.

The following procedure creates a named widget pool and creates a series of buttons in it:

p-dybut2.p
DEFINE VARIABLE num-buts  AS INTEGER.
DEFINE VARIABLE temp-hand AS WIDGET-HANDLE.

DEFINE FRAME butt-frame
   WITH WIDTH 60 CENTERED TITLE "Sales Representatives".

FORM
   salesrep
   WITH FRAME rep-frame.

CREATE WIDGET-POOL "rep-buttons".

num-buts = 0.
FOR EACH salesrep:
   CREATE BUTTON temp-hand IN WIDGET-POOL "rep-buttons"
         ASSIGN LABEL = salesrep.sales-rep
                FRAME = FRAME butt-frame:HANDLE
                ROW = TRUNC(num-buts / 3, 0) + 1
                COLUMN = ((num-buts MOD 3) * 20) + 1
                SENSITIVE = TRUE
         TRIGGERS:
            ON CHOOSE
               DO:
                 FIND salesrep WHERE salesrep.sales-rep = SELF:LABEL.
                 DISPLAY salesrep WITH FRAME rep-frame.
               END.
         END TRIGGERS.
   num-buts = num-buts + 1.
END.

FRAME butt-frame:HEIGHT-CHARS = (num-buts / 3) + 2.

VIEW FRAME butt-frame.

WAIT-FOR WINDOW-CLOSE OF CURRENT-WINDOW.

DELETE WIDGET-POOL "rep-buttons". 

The widget pool in this example is nonpersistent. Therefore, if you omit the DELETE WIDGET–POOL statement at the end of the procedure, the widget pool is automatically deleted when the procedure ends.

Because all the widgets in p-dybut2.p are created in the main procedure and are deleted at the end of the procedure, the widget pool does not need to be persistent. However, the following procedure requires a persistent widget pool. The following procedure, p-dybut3.p, accepts a month and year and then creates a button for each order entered during that month:

p-dybut3.p
DEFINE VARIABLE report-month AS INTEGER LABEL "Month" FORMAT ">9".
DEFINE VARIABLE report-year  AS INTEGER LABEL "Year" FORMAT "9999".
DEFINE VARIABLE temp-hand    AS WIDGET-HANDLE.

FORM
  report-month report-year
  WITH FRAME prompt-frame SIDE-LABELS.

DEFINE FRAME butt-frame WITH WIDTH 80.

ON GO OF FRAME prompt-frame
   DO:
       IF report-month:MODIFIED or report-year:MODIFIED
       THEN DO:
          ASSIGN report-month report-year.
          DELETE WIDGET-POOL "order-pool".
          RUN make-buttons.
       END.
   END.

ASSIGN report-month = MONTH(TODAY)
       report-year = YEAR(TODAY).

DISPLAY report-month report-year WITH FRAME prompt-frame.

RUN make-buttons.

ENABLE report-month report-year WITH FRAME prompt-frame.

DO ON ERROR UNDO, LEAVE ON ENDKEY UNDO, LEAVE ON STOP UNDO, LEAVE:
   WAIT-FOR WINDOW-CLOSE OF CURRENT-WINDOW.
END.

DELETE WIDGET-POOL "order-pool". 
PROCEDURE make-buttons: 
DEFINE VARIABLE num-buts  AS INTEGER.

   CREATE WIDGET-POOL "order-pool" PERSISTENT.
   num-buts = 0.
   FRAME butt-frame:HIDDEN = TRUE.
   FOR EACH order WHERE MONTH(order-date) = report-month AND
                        YEAR(order-date) = report-year:
      FRAME butt-frame:HEIGHT-CHARS = TRUNC(num-buts / 5, 0) + 3.
      CREATE BUTTON temp-hand IN WIDGET-POOL "order-pool"
              ASSIGN LABEL = STRING(order-num) + "/" + STRING(cust-num)
                     FRAME = FRAME butt-frame:HANDLE
                     ROW = TRUNC(num-buts / 5, 0) + 1
                     COLUMN = ((num-buts MOD 5) * 15) + 1
                     SENSITIVE = TRUE
              TRIGGERS:
                 ON CHOOSE
                    PERSISTENT RUN disp-order.
              END TRIGGERS.
      num-buts = num-buts + 1.
   END.

   FRAME butt-frame:HIDDEN = FALSE.
   IF num-buts = 0
   THEN MESSAGE "No orders found for" STRING(report-month) + "/" +
            STRING(report-year) VIEW-AS ALERT-BOX INFORMATION BUTTONS OK.
END PROCEDURE.

PROCEDURE disp-order:

FORM
   order
   WITH FRAME order-frame SIDE-LABELS.

   FIND order WHERE order-num =
          INTEGER(SUBSTRING(SELF:LABEL, 1, INDEX(SELF:LABEL, "/") - 1)).
   CREATE WINDOW temp-hand IN WIDGET-POOL "order-pool"
         ASSIGN TITLE = "Order Detail"
                VIRTUAL-HEIGHT-CHARS = FRAME order-frame:HEIGHT-CHARS.
   CURRENT-WINDOW = temp-hand.
   DISPLAY order WITH FRAME order-frame.
   CURRENT-WINDOW = DEFAULT-WINDOW.
END PROCEDURE. 

In this example, the widget pool is created within the internal procedure make–buttons. Because the buttons must be available outside the internal procedure, the widget pool must be persistent; otherwise the pool would be deleted at the end of the internal procedure. When you change the month or year value, the GO trigger deletes the widget pool (and therefore deletes all the buttons as well). It then runs make–buttons to create a new widget pool and a new set of buttons.

Note that the internal procedure, disp-order, creates a window in the persistent widget pool. When you change the month or year, any windows so created are deleted along with the buttons.

When you use a persistent widget pool you must make sure the pool is deleted. In p-dybut3.p the DO group surrounding the WAIT–FOR statement ensures that control will pass to the DELETE WIDGET–POOL statement no matter how you exit the procedure.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095