Dynamic browse, can't add triggers

Posted by OctavioOlguin on 06-Feb-2015 20:04

Hi there!!!!

I wonder why the following code won't fire triggers?

CREATE QUERY hQuery.
    
    hQuery:ADD-BUFFER(hBuffer).
    hQuery:SET-BUFFERS(hBuffer).
    hQuery:QUERY-PREPARE("FOR EACH ttResVent").
    hQuery:QUERY-OPEN.
    
    CREATE BROWSE hBrowse
        ASSIGN 
        X         = 10.29
        Y         = 163
        WIDTH     = 175
        DOWN      = 18.1
        QUERY     = hQuery
        FRAME     = FRAME {&FRAME-NAME}:HANDLE
        READ-ONLY = FALSE
        SENSITIVE = TRUE
        FONT      = 2
        
        TRIGGERS:
            ON RETURN ANYWHERE
                DO:
                    MESSAGE "return"
                        VIEW-AS ALERT-BOX.        
                END.
            ON DEFAULT-ACTION ANYWHERE
                DO:
                    MESSAGE "Default-action"
                        VIEW-AS ALERT-BOX.
                END.                
            ON F5 ANYWHERE
                DO:
                    MESSAGE "F5"
                        VIEW-AS ALERT-BOX.                    
                END.
        END TRIGGERS.    
Thanks in advance.

All Replies

Posted by Matt Gilarde on 07-Feb-2015 06:34

Can you attach the entire program? This section looks fine so the problem may lie somewhere else.

I noticed that you have "ANYWHERE" on the triggers. Are you expecting these triggers to fire even when the browse doesn't have focus? If so, it doesn't work that way. If you want these triggers to fire for any widget you need to move them out of the browse's trigger block.

Posted by OctavioOlguin on 07-Feb-2015 11:03

Thanks.

No... the anywhere was added by something I read in the help file, as I thought that the event was been caught by the row, and not by the browse itself.

here´s the program.

&ANALYZE-SUSPEND _VERSION-NUMBER AB_v10r12 GUI

&ANALYZE-RESUME

&Scoped-define WINDOW-NAME c-Win

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS c-Win

/*------------------------------------------------------------------------

 File:

 Description:

 Input Parameters:

     <none>

 Output Parameters:

     <none>

 Author:

 Created:

------------------------------------------------------------------------*/

/*          This .W file was created with the Progress AppBuilder.      */

/*----------------------------------------------------------------------*/

/* Create an unnamed pool to store all the widgets created

    by this procedure. This is a good default which assures

    that this procedure's triggers and internal procedures

    will execute in this procedure's storage, and that proper

    cleanup will occur on deletion of the procedure. */

CREATE WIDGET-POOL.

/* ***************************  Definitions  ************************** */

/* Parameters Definitions ---                                           */

/* Local Variable Definitions ---                                       */

DEFINE TEMP-TABLE ttResVent

   FIELD Sucursal     AS INTEGER

   FIELD Fecha        AS DATE

   FIELD Tickets      AS INTEGER

   FIELD Cancelados   AS INTEGER

   FIELD KilosMenudeo AS INTEGER

   FIELD kilosMayoreo AS INTEGER.

DEFINE VARIABLE hBrowse AS HANDLE NO-UNDO.

DEFINE VARIABLE hQuery  AS HANDLE NO-UNDO.

DEFINE VARIABLE hBuffer AS HANDLE NO-UNDO.

CREATE BUFFER hBuffer FOR TABLE "ttResVent".

DEFINE VARIABLE contadorCancelados AS INTEGER       NO-UNDO.

DEFINE VARIABLE ContadorTickets    AS INTEGER       NO-UNDO.

DEFINE VARIABLE sumaKilosMenudeo   AS DECIMAL       NO-UNDO.

DEFINE VARIABLE sumaKilosMayoreo   AS DECIMAL       NO-UNDO.

/* _UIB-CODE-BLOCK-END */

&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK

/* ********************  Preprocessor Definitions  ******************** */

&Scoped-define PROCEDURE-TYPE Window

&Scoped-define DB-AWARE no

/* Name of designated FRAME-NAME and/or first browse and/or first query */

&Scoped-define FRAME-NAME DEFAULT-FRAME

/* Standard List Definitions                                            */

&Scoped-Define ENABLED-OBJECTS fSucursal fNombreSucursal fDesde fHasta ~

bConsultar

&Scoped-Define DISPLAYED-OBJECTS fSucursal fNombreSucursal fDesde fHasta

/* Custom List Definitions                                              */

/* List-1,List-2,List-3,List-4,List-5,List-6                            */

/* _UIB-PREPROCESSOR-BLOCK-END */

&ANALYZE-RESUME

/* ***********************  Control Definitions  ********************** */

/* Define the widget handle for the window                              */

DEFINE VAR      c-Win              AS WIDGET-HANDLE NO-UNDO.

/* Definitions of the field level widgets                               */

DEFINE BUTTON bConsultar

   LABEL "Consultar"

   SIZE 15 BY 1.14.

DEFINE VARIABLE fDesde          AS DATE      FORMAT "99/99/99":U

   LABEL "Desde"

   VIEW-AS FILL-IN

   SIZE 14 BY 1 NO-UNDO.

DEFINE VARIABLE fHasta          AS DATE      FORMAT "99/99/99":U

   LABEL "Hasta"

   VIEW-AS FILL-IN

   SIZE 14 BY 1 NO-UNDO.

DEFINE VARIABLE fNombreSucursal AS CHARACTER FORMAT "X(256)":U

   VIEW-AS FILL-IN

   SIZE 42 BY 1 NO-UNDO.

DEFINE VARIABLE fSucursal       AS INTEGER   FORMAT "->,>>>,>>9":U INITIAL 0

   LABEL "Sucursal"

   VIEW-AS FILL-IN

   SIZE 14 BY 1 NO-UNDO.

/* ************************  Frame Definitions  *********************** */

DEFINE FRAME DEFAULT-FRAME

   fSucursal AT ROW 1.71 COL 24 COLON-ALIGNED WIDGET-ID 10

   fNombreSucursal AT ROW 1.71 COL 38.8 COLON-ALIGNED NO-LABEL WIDGET-ID 12 NO-TAB-STOP

   fDesde AT ROW 2.95 COL 24 COLON-ALIGNED WIDGET-ID 2

   fHasta AT ROW 4.19 COL 24 COLON-ALIGNED WIDGET-ID 4

   bConsultar AT ROW 4.33 COL 45 WIDGET-ID 6

   "sVen06001" VIEW-AS TEXT

   SIZE 15 BY .62 AT ROW 34.1 COL 2 WIDGET-ID 8

   FONT 20

   WITH 1 DOWN NO-BOX KEEP-TAB-ORDER OVERLAY

   SIDE-LABELS NO-UNDERLINE THREE-D

   AT COL 1 ROW 1

   SIZE 182 BY 33.95 WIDGET-ID 100.

/* *********************** Procedure Settings ************************ */

&ANALYZE-SUSPEND _PROCEDURE-SETTINGS

/* Settings for THIS-PROCEDURE

  Type: Window

  Allow: Basic,Browse,DB-Fields,Window,Query

  Other Settings: COMPILE

*/

&ANALYZE-RESUME _END-PROCEDURE-SETTINGS

/* *************************  Create Window  ************************** */

&ANALYZE-SUSPEND _CREATE-WINDOW

IF SESSION:DISPLAY-TYPE = "GUI":U THEN

   CREATE WINDOW c-Win ASSIGN

       HIDDEN             = YES

       TITLE              = "Resumen de ventas"

       HEIGHT             = 33.95

       WIDTH              = 182

       MAX-HEIGHT         = 33.95

       MAX-WIDTH          = 182

       VIRTUAL-HEIGHT     = 33.95

       VIRTUAL-WIDTH      = 182

       RESIZE             = YES

       SCROLL-BARS        = NO

       STATUS-AREA        = NO

       BGCOLOR            = ?

       FGCOLOR            = ?

       KEEP-FRAME-Z-ORDER = YES

       THREE-D            = YES

       MESSAGE-AREA       = NO

       SENSITIVE          = YES.

ELSE {&WINDOW-NAME} = CURRENT-WINDOW.

/* END WINDOW DEFINITION                                                */

&ANALYZE-RESUME

/* ***********  Runtime Attributes and AppBuilder Settings  *********** */

&ANALYZE-SUSPEND _RUN-TIME-ATTRIBUTES

/* SETTINGS FOR WINDOW c-Win

 VISIBLE,,RUN-PERSISTENT                                               */

/* SETTINGS FOR FRAME DEFAULT-FRAME

  FRAME-NAME                                                           */

ASSIGN

   fNombreSucursal:READ-ONLY IN FRAME DEFAULT-FRAME = TRUE.

IF SESSION:DISPLAY-TYPE = "GUI":U AND VALID-HANDLE(c-Win)

   THEN c-Win:HIDDEN = NO.

/* _RUN-TIME-ATTRIBUTES-END */

&ANALYZE-RESUME

/* ************************  Control Triggers  ************************ */

&Scoped-define SELF-NAME c-Win

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL c-Win c-Win

ON END-ERROR OF c-Win /* Resumen de ventas */

   OR ENDKEY OF {&WINDOW-NAME} ANYWHERE

   DO:

       /* This case occurs when the user presses the "Esc" key.

          In a persistently run window, just ignore this.  If we did not, the

          application would exit. */

       IF THIS-PROCEDURE:PERSISTENT THEN RETURN NO-APPLY.

   END.

/* _UIB-CODE-BLOCK-END */

&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL c-Win c-Win

ON WINDOW-CLOSE OF c-Win /* Resumen de ventas */

   DO:

       /* This event will close the window and terminate the procedure.  */

       APPLY "CLOSE":U TO THIS-PROCEDURE.

       RETURN NO-APPLY.

   END.

/* _UIB-CODE-BLOCK-END */

&ANALYZE-RESUME

&Scoped-define SELF-NAME bConsultar

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL bConsultar c-Win

ON CHOOSE OF bConsultar IN FRAME DEFAULT-FRAME /* Consultar */

   DO:

       ASSIGN FRAME {&FRAME-NAME} fDesde fHasta fSucursal.

       {procs\inc\wait.i}

       EMPTY TEMP-TABLE ttResVent.

       FOR EACH dwTicket

           WHERE dwTicket.fecha >= fDesde

           AND dwTicket.Fecha <= fHasta

           AND (dwTicket.Sucursal = fSucursal OR fSucursal = 0)

           GROUP BY dwTicket.Sucursal

           BY dwTicket.Fecha:

           IF FIRST-OF(dwTicket.Fecha) THEN

           DO:

               ASSIGN

                   contadorCancelados = 0

                   sumaKilosMenudeo   = 0

                   sumaKilosMayoreo   = 0

                   ContadorTickets    = 0.

           END.

           IF dwTicket.StatusDoc = "C" THEN

               ASSIGN contadorCancelados = contadorCancelados + 1.

           ELSE

           DO:

               ASSIGN

                   COntadorTickets = ContadorTickets + 1.

               FOR EACH dwTicketD OF dwTicket NO-LOCK:

                   IF dwTicketD.Control# = 0 THEN

                       ASSIGN

                           sumaKilosMenudeo = sumaKilosMenudeo + dwTicketD.Cantidad.                

                   ELSE

                       ASSIGN            

                           sumaKilosMayoreo = sumaKilosMayoreo + dwTicketD.Cantidad.    

               END.

               IF LAST-OF(dwTicket.Fecha) THEN

               DO:

                   CREATE ttResVent.

                   ASSIGN

                       ttResVent.Sucursal     = dwTicket.Sucursal

                       ttResVent.Fecha        = dwTicket.fecha

                       ttResVent.Tickets      = ContadorTickets

                       ttResVent.Cancelados   = contadorCancelados

                       ttResVent.KilosMenudeo = sumaKilosMenudeo

                       ttResVent.kilosMayoreo = sumaKilosMayoreo.

               END.  

           END.

       END.

       hQuery:QUERY-PREPARE("FOR EACH ttResVent").

       hQuery:QUERY-OPEN.

   END.

/* _UIB-CODE-BLOCK-END */

&ANALYZE-RESUME

&Scoped-define SELF-NAME fSucursal

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL fSucursal c-Win

ON LEAVE OF fSucursal IN FRAME DEFAULT-FRAME /* Sucursal */

   DO:

       ASSIGN FRAME {&FRAME-NAME} {&SELF-NAME}.

       IF {&SELF-NAME} = 0 THEN

       DO:

           DISPLAY "Todas" @ fNombreSucursal WITH FRAME {&FRAME-NAME}.            

       END.

       ELSE

       DO:

           FIND Sucursal NO-LOCK

               WHERE Sucursal.Sucursal = {&SELF-NAME}.

           DISPLAY Sucursal.Nombre @ fNombreSucursal WITH FRAME {&FRAME-NAME}.

       END.  

   END.

/* _UIB-CODE-BLOCK-END */

&ANALYZE-RESUME

&UNDEFINE SELF-NAME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK c-Win

/* ***************************  Main Block  *************************** */

/* Set CURRENT-WINDOW: this will parent dialog-boxes and frames.        */

ASSIGN CURRENT-WINDOW                = {&WINDOW-NAME}

      THIS-PROCEDURE:CURRENT-WINDOW = {&WINDOW-NAME}.

/* The CLOSE event can be used from inside or outside the procedure to  */

/* terminate it.                                                        */

ON CLOSE OF THIS-PROCEDURE

   RUN disable_UI.

/* Best default for GUI applications is...                              */

PAUSE 0 BEFORE-HIDE.

/* Now enable the interface and wait for the exit condition.            */

/* (NOTE: handle ERROR and END-KEY so cleanup code will always fire.    */

MAIN-BLOCK:

DO ON ERROR   UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK

   ON END-KEY UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK:

   RUN ArmaBrowse.    

   RUN enable_UI.

   IF NOT THIS-PROCEDURE:PERSISTENT THEN

       WAIT-FOR CLOSE OF THIS-PROCEDURE.

END.

/* _UIB-CODE-BLOCK-END */

&ANALYZE-RESUME

/* **********************  Internal Procedures  *********************** */

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE ARmaBrowse c-Win

PROCEDURE ARmaBrowse :

   /*------------------------------------------------------------------------------

        Purpose:

        Notes:

        ------------------------------------------------------------------------------*/    

   CREATE QUERY hQuery.

   hQuery:ADD-BUFFER(hBuffer).

   hQuery:SET-BUFFERS(hBuffer).

   hQuery:QUERY-PREPARE("FOR EACH ttResVent").

   hQuery:QUERY-OPEN.

   CREATE BROWSE hBrowse

       ASSIGN

       X         = 10.29

       Y         = 163

       WIDTH     = 175

       DOWN      = 20.2

       QUERY     = hQuery

       FRAME     = FRAME {&FRAME-NAME}:HANDLE

       READ-ONLY = FALSE

       SENSITIVE = TRUE

       FONT      = 2

       TRIGGERS:

           ON RETURN ANYWHERE

               DO:

                   MESSAGE "return"

                       VIEW-AS ALERT-BOX.        

               END.

           ON DEFAULT-ACTION ANYWHERE

               DO:

                   MESSAGE "Default-action"

                       VIEW-AS ALERT-BOX.

               END.                

           ON F5 ANYWHERE

               DO:

                   MESSAGE "F5"

                       VIEW-AS ALERT-BOX.                    

               END.

       END TRIGGERS.    

   /* hBuffer:BUFFER-FIELD("ttResVent.Sucursal"):BUFFER-VALUE  -  para referenciar un campo del buffer dinamico */

   hBrowse:ADD-LIKE-COLUMN("ttResVent.Fecha").

   hBrowse:ADD-LIKE-COLUMN("ttResVent.Sucursal").

   hBrowse:ADD-LIKE-COLUMN("ttResVent.Tickets").

   hBrowse:ADD-LIKE-COLUMN("ttResVent.Cancelados").

   hBrowse:ADD-LIKE-COLUMN("ttResVent.KilosMenudeo").

   hBrowse:ADD-LIKE-COLUMN("ttResVent.KilosMayoreo").

   ASSIGN

       fDesde = TODAY

       fHasta = TODAY.

END PROCEDURE.

/* _UIB-CODE-BLOCK-END */

&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE disable_UI c-Win  _DEFAULT-DISABLE

PROCEDURE disable_UI :

   /*------------------------------------------------------------------------------

     Purpose:     DISABLE the User Interface

     Parameters:  <none>

     Notes:       Here we clean-up the user-interface by deleting

                  dynamic widgets we have created and/or hide

                  frames.  This procedure is usually called when

                  we are ready to "clean-up" after running.

   ------------------------------------------------------------------------------*/

   /* Delete the WINDOW we created */

   IF SESSION:DISPLAY-TYPE = "GUI":U AND VALID-HANDLE(c-Win)

       THEN DELETE WIDGET c-Win.

   IF THIS-PROCEDURE:PERSISTENT THEN DELETE PROCEDURE THIS-PROCEDURE.

END PROCEDURE.

/* _UIB-CODE-BLOCK-END */

&ANALYZE-RESUME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE enable_UI c-Win  _DEFAULT-ENABLE

PROCEDURE enable_UI :

   /*------------------------------------------------------------------------------

     Purpose:     ENABLE the User Interface

     Parameters:  <none>

     Notes:       Here we display/view/enable the widgets in the

                  user-interface.  In addition, OPEN all queries

                  associated with each FRAME and BROWSE.

                  These statements here are based on the "Other

                  Settings" section of the widget Property Sheets.

   ------------------------------------------------------------------------------*/

   DISPLAY fSucursal fNombreSucursal fDesde fHasta

       WITH FRAME DEFAULT-FRAME IN WINDOW c-Win.

   ENABLE fSucursal fNombreSucursal fDesde fHasta bConsultar

       WITH FRAME DEFAULT-FRAME IN WINDOW c-Win.

   {&OPEN-BROWSERS-IN-QUERY-DEFAULT-FRAME}

   VIEW c-Win.

END PROCEDURE.

/* _UIB-CODE-BLOCK-END */

&ANALYZE-RESUME

Posted by Matt Gilarde on 07-Feb-2015 11:29

The triggers are scoped to the procedure in which they are defined and they go out of scope when procedure ArmaBrowse ends. To fix this you need to move the trigger code into procedures and run the procedures from the TRIGGERS block with PERSISTENT RUN.

For example, add a procedure like this:

PROCEDURE ArmaBrowseReturnTrigger:

      MESSAGE "return"

          VIEW-AS ALERT-BOX.        

END.

And change the TRIGGERS block like this:

TRIGGERS:

     ON RETURN ANYWHERE

          PERSISTENT RUN ArmaBrowseReturnTrigger.

 [... other triggers ...]

END TRIGGERS.    

Posted by OctavioOlguin on 07-Feb-2015 13:21

Thanks!!!

And at the end of procedure, should I do something? like terminate persistent procedure or something?

would it be "elegant" to make the main block big enough to contain the browse definition and so this way get into scope the trigger procedures?

Thanks again.

Posted by Matt Gilarde on 07-Feb-2015 15:21

You don't have to do anything to clean up the persistent trigger. It will be cleaned up automatically, I believe when the main block goes out of scope.

Yes, creating the browse in the main block will also fix the scoping problem. I won't comment on whether that would be elegant or not.

Posted by James Palmer on 07-Feb-2015 16:43

Whether it's elegant or not, building the browse in the main block is surely going to be inconvenient. What happens if for some reason you end up needing to rebuild the browse?
As for the persistent triggers, as far as I recall they are scoped to the widget pool.

James Palmer | Application Developer
Tel: 01253 785103

[collapse] From: Matt Gilarde
Sent: ‎07/‎02/‎2015 21:24
To: TU.OE.General@community.progress.com
Subject: RE: [Technical Users - OE General] Dynamic browse, can't add triggers

Reply by Matt Gilarde

You don't have to do anything to clean up the persistent trigger. It will be cleaned up automatically, I believe when the main block goes out of scope.

Yes, creating the browse in the main block will also fix the scoping problem. I won't comment on whether that would be elegant or not.

Stop receiving emails on this subject.

Flag this post as spam/abuse.




This email has been scanned for email related threats and delivered safely by Mimecast.
For more information please visit http://www.mimecast.com
[/collapse]

Posted by OctavioOlguin on 08-Feb-2015 21:12

Thanks both of you.

By "elegant" I was meaning more precise about if it was convenient, or better practices to define the browse in the main block,instead of a procedure.

You mention about rebuilding the browse... that mean that I can switch tables, columns, query and everything inside the browse, don´t you?

Mmmmh.. haven't tought of that before...  Now I do make a question about elegance indeed...   what if when user applies default-action to this browse with accumulative numers, we swept the contents, and then open a query with details of that particular row....  mmmh sound something interesting to test.... What do you think?

This thread is closed