Kbase P32670: Dynamic SDB: how to use the ROW-DISPLAY trigger in order to change the attribute of a row?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  4/12/2005 |
|
Status: Verified
GOAL:
Dynamic SDB: how to use the ROW-DISPLAY trigger in order to change the attribute of a row?
GOAL:
How to avoid error 4477 from a row-display trigger.
GOAL:
Cannot be set within a ROW-DISPLAY trigger for . (4477)
GOAL:
How to avoid error 5906 from a row-display trigger
GOAL:
Cannot be queried within a ROW-DISPLAY trigger for . (5906)
FIX:
Let say that what we want to achieve is to change the color of the row in which the customer credit is above 2000. This is a step by step sample on how to achieve this. It works against sports2000 database.
1) Define an SDO using a query with all the customer field and include it your smart window.
2) Select a Dynamic SmartDataBrowser from the palette and drop it in the smart window.
3) Uncheck 'Open query on initialization' on the SDO Properties dialog box.
4) Now we have to use a temp-table to move through the columns of a browse in a row-display trigger to set the FGCOLOR and BGCOLOR attributes in order to avoid error 4407. Add the following code sections to the window containing the SDB.
* Definitions Section */
DEFINE TEMP-TABLE ttBrws NO-UNDO
FIELD BrwsHdl AS HANDLE
FIELD BrwsName AS CHARACTER
INDEX BrwsHdl IS PRIMARY UNIQUE BrwsHdl.
DEFINE TEMP-TABLE ttCol NO-UNDO
FIELD BrwsHdl AS HANDLE
FIELD ColHdl AS HANDLE
FIELD ColName AS CHARACTER
FIELD ColWidth AS DECIMAL
FIELD ColFormat AS CHARACTER
FIELD ColDatTyp AS CHARACTER
FIELD ColLabel AS CHARACTER
INDEX BrwsCol IS PRIMARY UNIQUE BrwsHdl ColHdl.
/* Procedure Definitions Section */
PROCEDURE GetColInfo:
DEFINE INPUT PARAMETER hBrws AS HANDLE NO-UNDO.
DEFINE VARIABLE hCol AS HANDLE NO-UNDO.
ASSIGN hCol = hBrws:FIRST-COLUMN.
CREATE ttBrws.
ASSIGN
ttBrws.BrwsHdl = BROWSE {&BROWSE-NAME}:HANDLE
ttBrws.BrwsName = ttBrws.BrwsHdl:NAME.
DO WHILE VALID-HANDLE(hCol):
IF NOT CAN-FIND(FIRST ttCol WHERE
ttCol.BrwsHdl = hBrws AND
ttCol.ColHdl = hCol) THEN
DO:
CREATE ttCol.
ASSIGN
ttCol.BrwsHdl = hBrws
ttCol.ColHdl = hCol
ttCol.ColName = hCol:NAME
ttCol.ColWidth = hCol:WIDTH
ttCol.ColFormat = hCol:FORMAT
ttCol.ColDatTyp = hCol:DATA-TYPE
ttCol.ColLabel = hCol:LABEL.
END.
hCol = hCol:NEXT-COLUMN.
END.
END PROCEDURE.
5) Create an override on the initializeObject procedure:
/* Code placed here will execute PRIOR to standard behavior. */
DEFINE VARIABLE h AS HANDLE NO-UNDO.
h = DYNAMIC-FUNCTION('getBrowseHandle':U IN h_dynbrowser).
ON 'ROW-DISPLAY':U OF h PERSISTENT RUN MyRowDisplay IN THIS-PROCEDURE (INPUT h, "*" ).
RUN SUPER.
/* Code placed here will execute AFTER standard behavior. */
RUN GetColInfo (h).
/* do not forget to uncheck openQuery property in SDO */
DYNAMIC-FUNCTION('openQuery':U IN h_dcustomer).
END PROCEDURE.6) Create an internal function MyRowDisplay:
DEFINE INPUT PARAMETER phBrwsHdl AS HANDLE NO-UNDO.
DEFINE INPUT PARAMETER pcColList AS CHARACTER NO-UNDO.
FOR EACH ttCol NO-LOCK WHERE ttCol.BrwsHdl = phBrwsHdl:
IF CAN-DO(pcColList,ttCol.ColName) OR pcColList = "*"
THEN IF INT (DYNAMIC-FUNCTION('columnStringValue':U IN h_dcustomer,
INPUT "balance") ) > 2000
THEN ASSIGN
ttCol.ColHdl:BGCOLOR = 5
ttCol.ColHdl:FGCOLOR = 3.
END.
END PROCEDURE.