Kbase P16818: ADM2 - How to initialize a Combo-Box using PUBLISH & SUBSCRI
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  6/25/2003 |
|
Status: Unverified
GOAL:
ADM2 - How to initialize a Combo-Box using PUBLISH & SUBSCRIBE when the Combo-Box is using LIST-ITEM-PAIRS
FACT(s) (Environment):
Progress 9.x
FIX:
The following is a step by step description of how to populate a COMBO-BOX or a SELECTION-LIST using the PUBLISH and SUBSCRIBE statements:
1) Start the AppBuilder and connect to the Sports2000 database.
2) Create a SmartDataObject (SDO) against the customer table to include the
CustNum, Name, Country and SalesRep fields and save it as dCustomer.w.
3) Create a SmartDataObject (SDO) against the SalesRep table to include the
SalesRep field and save it as dSalesRep.w.
4) Create a SmartDataViewer (SDV) against the Customer SDO to include the
CustNum, Name, and Country fields and save it as vCustomer.w.
5) Drop the SalesRep SmartDataObject dSalesRep.w onto the Customer
SmartDataViewer.
6) Drop a combo-box from the object palette onto the SmartDataViewer. Use the
combo-box property sheet to name it SalesRep, label it Sales Rep and change
the type to 'List-Item-Pairs'. Use the database field icon of the property
sheet to map it to the SalesRep field.
7) Place the following code before the "RUN SUPER" statement in the
initializeObject procedure of the Customer SmartDataViewer:
DO WITH FRAME {&FRAME-NAME}:
PUBLISH "LoadSalesRepList" (INPUT RowObject.SalesRep:HANDLE).
END.
8) Create the procedure LoadSalesRepList in the SalesRep SDO with the
following code:
DEFINE INPUT PARAMETER hWidget AS HANDLE NO-UNDO.
/* Please note that this code changes the RepName field and replaces */
/* commas with an empty string. This is done because the default */
/* delimiter for a combo-box is the comma. If the customers */
/* application code needs to show the commas then the DELIMITER */
/* attribute for the combo-box should be changed to something else. */
DEFINE VARIABLE cDelimiterFix AS CHARACTER NO-UNDO.
IF VALID-HANDLE(hWidget) THEN
IF hWidget:TYPE = "COMBO-BOX" THEN
DO:
ASSIGN hWidget:LIST-ITEM-PAIRS = ?.
RUN fetchFirst.
REPEAT:
ASSIGN cDelimiterFix = REPLACE(RowObject.RepName,","," ").
hWidget:ADD-LAST(cDelimiterFix, RowObject.SalesRep).
IF INDEX("LastRecord,OnlyRecord", DYNAMIC-FUNCTION('getQueryPosition':U)) = 0 THEN
RUN fetchNext.
ELSE
LEAVE.
END.
END.
9) Place the following code before the "RUN SUPER" statement in the
initializeObject procedure of the SalesRep SmartDataObject:
SUBSCRIBE TO "LoadSalesRepList" ANYWHERE.
10) Create a new application to include SmartWindowObject containing the
Customer SmartDataObject, the Customer SmartDataViewer, a smart toolbar
and the following SmartLinks:
Link Type Source Object Target Object
---------- ------------- -------------
DATA h_dCustomer h_vCustomer
NAVIGATION h_dyntoolbar h_dCustomer
TABLEIO h_dyntoolbar h_vCustomer
UPDATE h_vCustomer h_dCustomer
11) Save and run this application.