Answered Create some dynami triggers

Hi everyone,

I have a new one for you.

This is my case:
I have a Window app with a Temp-Table in parameter, and a list of the field I want to display:

Code:
DEFINE INPUT PARAMETER cListData AS CHARACTER. /* My list of field (index of the extent) */
DEFINE INPUT PARAMETER cListCol  AS CHARACTER. /* Column-label */

DEFINE TEMP-TABLE TT1
    FIELD data AS CHARACTER EXTENT 102.


So I was able to create the field in my browse BR-TT1 and make them updatable like this:
Code:
DEFINE VARIABLE iCmpt AS INTEGER     NO-UNDO.

DEFINE VARIABLE hCol  AS HANDLE      NO-UNDO.

DEFINE VARIABLE hTT   AS HANDLE      NO-UNDO.
DEFINE VARIABLE hTTF AS HANDLE      NO-UNDO.

ASSIGN
    hBR = BR-TT1:HANDLE IN FRAME F-Main
    hBR:READ-ONLY = FALSE
    hTT = TEMP-TABLE TT1:HANDLE.

DO iCmpt = 1 TO NUM-ENTRIES(cListData) :
    
    ASSIGN
        hCol              = hBR:ADD-LIKE-COLUMN("TT1.data[" + ENTRY(iCmpt, cListData) + "]")
        hCol:LABEL        = ENTRY(iCmpt, cListCol)
        hCol:WIDTH-PIXELS = func-widthcolumn(hCol) 
        hCol:READ-ONLY    = FALSE
        hTTF              = hTT:DEFAULT-BUFFER-HANDLE:BUFFER-FIELD('data')
        hTTF:FORMAT       = "X(40)".
         
END.

But now I need to create some triggers to manage the changed I can make on my browse .

Or maybe there is another way that I'm willing to take.

So if you can help it would be greet :)

Best regards :)

- BobyIsProgress -
 

Cringer

ProgressTalk.com Moderator
Staff member
Not sure I understand the question. It's still a static browse, right? So you just add triggers to the static browse?
 
Yes I think, I create it with the appbuilder tools.

I will try to turn my question arround.

So in this browser I create dynamicly the columns I want to show with the code I posted before:
DEFINE VARIABLE iCmpt AS INTEGER NO-UNDO.

DEFINE VARIABLE hCol AS HANDLE NO-UNDO.

DEFINE VARIABLE hTT AS HANDLE NO-UNDO.
DEFINE VARIABLE hTTF AS HANDLE NO-UNDO.

ASSIGN
hBR = BR-TT1:HANDLE IN FRAME F-Main
hBR:READ-ONLY = FALSE
hTT = TEMP-TABLE TT1:HANDLE.

DO iCmpt = 1 TO NUM-ENTRIES(cListData) :

ASSIGN
hCol = hBR:ADD-LIKE-COLUMN("TT1.data[" + ENTRY(iCmpt, cListData) + "]")
hCol:LABEL = ENTRY(iCmpt, cListCol)
hCol:WIDTH-PIXELS = func-widthcolumn(hCol)
hCol:READ-ONLY = FALSE
hTTF = hTTF:DEFAULT-BUFFER-HANDLE:BUFFER-FIELD('data')
hTTF:FORMAT = "X(40)".

END.


And my Browse is updatable. But I don't manage to update the temp-table field with the value I write on the browse cell ....

I was reading on other forum (can't manage to find the article) that I have to create some triggers like this
Code:
ON 'LEAVE':U OF /* my TT field like TT1.data[1] */  DO: /* procedere or function call */  RETURN. END .

But because my field are not set up at compiled time I can't manage to use this solution.

Do you have a solution ?

Best Regards,

- BobyIsProgress -
 

Osborne

Active Member
Based on this article - Progress KB - How to ENABLE/DISABLE browse fields at runtime - when the browse has the relevant columns get the handle of the browse, read the columns and set the triggers.

Something like this:
Code:
DO iCounter = 1 TO hBrowse:NUM-COLUMNS:
   hColumn = hBrowse:GET-BROWSE-COLUMN(iCounter).
   IF hColumn:NAME = "relevant column" THEN DO:
      ON LEAVE OF hColumn DO:
         ...
      END.
      ON VALUE-CHANGED OF hColumn DO:
         ...
      END.
   END.
END.
 
Based on this article - Progress KB - How to ENABLE/DISABLE browse fields at runtime - when the browse has the relevant columns get the handle of the browse, read the columns and set the triggers.

Something like this:
Code:
DO iCounter = 1 TO hBrowse:NUM-COLUMNS:
   hColumn = hBrowse:GET-BROWSE-COLUMN(iCounter).
   IF hColumn:NAME = "relevant column" THEN DO:
      ON LEAVE OF hColumn DO:
         ...
      END.
      ON VALUE-CHANGED OF hColumn DO:
         ...
      END.
   END.
END.


Hi thank you for your advice. But it seems that the trigger doesn't work.

In the same times I write this on the "ROW-LEAVE" trigger of the BROWSE and it works, but I have to go through all the column to find my difference between value .


Code:
DO iCmpt = 1 TO NUM-ENTRIES(cListData) :
        hCol = hBR:GET-BROWSE-COLUMN(iCmpt) .

        IF TT1.data[INT(ENTRY(iCmpt, cListData))] <> hCol:SCREEN-VALUE THEN
            MESSAGE "TT : " TT1.data[INT(ENTRY(iCmpt, cListData))] SKIP
                    "BR : " hCol:SCREEN-VALUE 
                VIEW-AS ALERT-BOX INFO BUTTONS OK.
    END.
 

Osborne

Active Member
No difference really as just using a different method to access the browse column.

If you only need to check on a single column, then instead of looping through the columns each time or using temp-tables, just use a variable to store the required column handle and reference that in the required part of the program:

Code:
/* Only need to do this once to store the column handle */
DO iCounter = 1 TO hBrowse:NUM-COLUMNS:
   hColumn = hBrowse:GET-BROWSE-COLUMN(iCounter).
   IF hColumn:NAME = "relevant column" THEN DO:
      hBRCol = hColumn.
      LEAVE.
   END.
END.
...
ON ROW-LEAVE OF hBrowse DO:
   IF VALID-HANDLE(hBRCol) AND
      TT1.data[INT(ENTRY(iCmpt, cListData))] <> hBRCol:SCREEN-VALUE THEN DO:
      MESSAGE "TT : " TT1.data[INT(ENTRY(iCmpt, cListData))] SKIP
              "BR : " hBRCol:SCREEN-VALUE 
              VIEW-AS ALERT-BOX INFO BUTTONS OK.
      ...
   END.
END.

Something similar to this example that shows how to access a browse calculated column:

 
The thing is I can have to change the value on other column and not only one or two predefined column.

So I keep my solution for now. But i saved your solution @Osborne for when I will need it.

Thank you all for your advice and help as always :D

best Regards
 
Top