Progress
ADM 2 Guide


Creating the myviewer Class

The example in this section illustrates creating a new class based on the viewer class. The new class, called myviewer, will contain custom functionality that displays a warning message to an application user who wants to delete a record and allows the user to choose how to proceed. This functionality will be built into all SmartObjects based on this class.

The following sections describe how to create the new myviewer class files, then modify them to create the new functionality.

NOTE: The example assumes that you installed Progress in the D:\PROGRESS directory.

Creating the myviewer Class Files

Follow these steps to create the myviewer class files:

  1. From the AppBuilder main menu, choose the Tools New ADM Class... command:
  2. The New ADM Class dialog box opens, with the Basic tab in front.

  3. Type myviewer, the new class name, in the Name field:
  4. Note that when you type myviewer, the AppBuilder enters default directories in the directory fill-in fields and names based on myviewer in many of the filename fill-in fields; for example, myviprop.i for the property filename.

  5. Select the class from which to derive the myviewer class:
    1. Click on the Class button next to the Derive From Class field. In the Choose Class Definition dialog box that appears, you are placed by default in the %DLC%\src\adm2 directory.
    2. Select the viewer.cld class definition file in that directory, then choose Open.
    3. The AppBuilder adds information to the New ADM Class dialog box:

      Note that the Derive From Class field now contains the viewer.cld class definition file. Note also that the Copy From Template field is automatically filled with the filename of the viewer template. This happens only because the class definition file contains a definition of this template; if it did not, this field would stay empty.

  6. Click the Custom Files tab to note the custom class files that will be generated for the myviewer class:
  7. Click the Basic tab, then click to check the Open files in the AppBuilder once generated check box at the bottom of this tab. This instructs the AppBuilder to open the primary include file, the property file, the super procedure file, and the prototype file after creating the class files:
  8. Press OK to create the files.
  9. After the AppBuilder finishes creating the myviewer class files, close the primary include file (myviewer.i) and the prototype file (myviprto.i); these files do not need modification in this example.
Modifying the myviewer Standard Class Files

You use the following new code to implement the custom myviewer functionality: a DeleteMessage property, a setDeleteMessage function, and an override procedure for the standard ADM deleteRecord method. Adding this functionality requires changes only to the myviprop.i property file and the myviewer.p super procedure file, both of which should still be open in the AppBuilder.

Follow these steps in the AppBuilder to add the new functionality:

  1. Define the new DeleteMessage property in the myviprop.i property file. To do this, go to the file’s main block and add the code shown in bold typeface:
  2. /* Include the file that defines prototypes for all of the super
         procedure’s entry points.
         And skip including the prototypes if we are *any* super procedure. */
    &IF "{&ADMSuper}":U EQ "":U &THEN
      {src/adm2/myviprto.i}
    &ENDIF
    
      /* Put your xp{&Property} preprocessor definition here.
         Use the following format, e.g.,
         &GLOBAL-DEFINE xpMyProperty
         These preprocessors tell at compile time which properties can
         be retrieved directly from the temp-table */
    
         &GLOBAL-DEFINE xpDeleteMessage
    
      {src/adm2/viewprop.i}
    
    &IF "{&ADMSuper}":U = "":U &THEN
      /* Put your property field definition here.
         Use the following syntax, e.g.,
         ghADMProps:ADD-NEW-FIELD(’MyProperty’:U, ’CHAR’:U, ,’x(20)’:U, 
    ’Hi’:U). */
    
         ghADMProps:ADD-NEW-FIELD(’DeleteMessage’:U, ’CHAR’:U, 0, ?,
                                 ’Are you sure you want to delete this record?’:U).
    &ENDIF
    
      {src/adm2/custom/myvipropcustom.i} 
    

    When you finish making these changes, click on the Save button (the diskette icon) on the AppBuilder main window to save your changes, then close the property file window.

  3. Create a new setDeleteMessage function in the myviewer.p super procedure file. This function allows you to set the new DeleteMessage property. To create the new function, add the code shown in bold typeface:
  4. RETURNS LOGICAL
      ( INPUT pcDeleteMessage AS CHARACTER ) :
    /*-------------------------------------------------------------------
      Purpose:
        Notes:
      -------------------------------------------------------------------*/
      {set DeleteMessage pcDeleteMessage}.
      
      RETURN TRUE.   /* Function return value. */
    END FUNCTION. 
    

  5. Create a new override procedure for the deleteRecord method in the myviewer.p super procedure file. This procedure displays an alert box when the deleteRecord method is invoked; this alert box prompts the user with a message that corresponds to the value of the new DeleteMessage property: if the user chooses Yes, the ADM deleteRecord executes, otherwise it returns without executing. To create the new override procedure, add the code shown in bold typeface:
  6. /*-------------------------------------------------------------------
      Purpose:     
      Parameters:  <none>
      Notes:       
    -------------------------------------------------------------------*/
      DEFINE VARIABLE cDeleteMessage AS CHARACTER   NO-UNDO.
      
      {get DeleteMessage cDeleteMessage}.
      MESSAGE cDeleteMessage
        VIEW-AS ALERT-BOX QUESTION
        BUTTONS YES-NO
        UPDATE lAnswer AS LOGICAL.
      
      IF lAnswer THEN 
        RUN SUPER.
    
    END PROCEDURE. 
    

    When you finish making the changes in Steps 2 and 3, click on the Save button (the diskette icon) on the AppBuilder main window to save your changes, then close the super procedure file window. The AppBuilder now creates a .r version of the super procedure in the src\adm2 directory under your working directory.

  7. Enable the new super procedure file by moving the .r file from the src\adm2 directory under your working directory into the adm2 directory under your working directory.
  8. NOTE: If you do not move the .r file into the adm2 directory under your working directory, you will not be able to use the new super procedure.

  9. Make the template for the myviewer class available on the New dialog box that appears when you choose File New from the AppBuilder menu. To do this:
    1. Create a new .cst file and add to it the following code lines:
    2. *NEW-SMARTOBJECT  SmartDataViewer Demo
      NEW-TEMPLATE    src/adm2/template/myviewer.w 
      

    3. Put the .cst file into the src\adm2\template directory under your working directory.
    4. Load the new .cst file by choosing Menu Use Customº from the AppBuilder Palette window and adding the name of the new file to the list.

The new class, with its custom behavior, is now ready for use. Before you work with it, you should restart the AppBuilder to re-establish the super procedure stack.


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