skip to main content
OpenEdge Development: ADM Reference
ADM2 SmartObject API Reference : Reading and writing object properties
 
Reading and writing object properties
Every SmartObject makes its public properties available to other objects. The other objects might be other SmartObjects, non-Smart ABL code, or non-OpenEdge modules using the Open4GL interface.
The standard properties for an object type are defined in the ADMProps temp-table. That table and its global handle ghADMProps are declared in the file smrtprop.i. Fields in the table represent individual properties, and are defined by the class that needs them. For example, a SmartDataObject has properties defined in dataprop.i, qryprop.i, and smrtprop.i, and smrtprop.i declares the ADMProps table and defines properties common to all SmartObjects, qryprop.i adds properties common to all query-based objects, and finally dataprop.i adds the properties specific to the SmartDataObject.
Refer to Figure 1–1 to see the inheritance hierarchy for each object class.
get(propname) and set(propname) functions
Every public-readable property must have a function defined to return the current value of the property. Similarly, every public-writable property must have a function defined to set a new value for the property. These functions conform to certain conventions:
*get — The get function identifier takes the form getpropname. The function accepts no arguments, and returns the current value of the property. It can also perform other processing, if needed.
*set — The set function identifier takes the form setpropname. It accepts a single argument—the new value for the property—and returns TRUE/FALSE depending on whether it succeeded in changing the value. It can perform additional processing, if needed.
A very small number of these functions vary slightly from the model described here, but these differences are not significant.
{get} and {set} pseudo-functions
In addition to the conventional get and set functions, the ADM supports a pseudo-function syntax for use in super-procedure files particularly. These pseudo-functions are implemented by the include files get and set (not get.i or set.i) located in the tty and gui directories.
A call to {get} takes one of the following forms:
 
{get propname returnvar}.
{get propname returnvar ownerhandle}
Where propname is the property name in the TARGET-PROCEDURE object and returnvar is the variable into which the value is to be returned. If the property does not belong to the TARGET-PROCEDURE object, provide the appropriate handle in ownerhandle.
The {set} syntax is very similar:
 
Syntax 
{set propname newvalue}
{set propname newvalue ownerhandle}
 
The only difference between {get} and {set} syntax is that the second {set} argument is the new value for the property.
The need for two different syntaxes
Properties store the current state of the object, so reading and writing them is a high-frequency activity. It pays to optimize high-frequency activities, even when the net gain per operation is small. The pseudo-functions provide that slight optimization, and should be used in code that runs inside a SmartObject. Code that runs outside the Smart world—basic ABL and Open4GL routines—should use the conventional get/set functions.
Figure 1–2 shows the {get} code reformatted and commented. The {set} code is very similar.
 
/* {get propname returnvar [ownerhandle]} */
&IF "{3}":U = "":U &THEN                  /* no handle is passed in, but */ 
  &IF DEFINED(xp{1}) NE 0 &THEN           /* there is an xp macro defined */
    ASSIGN 
      ghProp = WIDGET-HANDLE(             /* pick up the handle to the */
       ENTRY(1,                           /* target proc’s ADM-DATA table */
       TARGET-PROCEDURE:ADM-DATA,   
       CHR(1)))                   
     ghProp = ghProp:BUFFER-FIELD('{1}':U) /* then pick up the handle */
                                           /* to the slot for the prop */
     {2} = ghProp:BUFFER-VALUE.            /* and finally assign the */
                                           /* value in the slot to */ 
                                           /* the prop var passed in and */
&ELSE                                      /* there is no xp macro defined */
  {2} = DYNAMIC-FUNCTION(
          "get{1}":U IN TARGET-PROCEDURE). /* set the prop var by */
                                           /* building and firing a call */
                                           /* to the ordinary function */
&ENDIF                                     /* end xp-macro-defined */
&ELSE                                      /* a handle was passed in... */
  &IF DEFINED(xp{1}) NE 0 &THEN            /* and if there is an xp macro */
    ASSIGN 
     ghProp = WIDGET-HANDLE(               /* pick up the handle to */
       ENTRY(1,                            /* the passed-in handle’s */ 
       {3}:ADM-DATA,                       /* props table */
       CHR(1))) 
     ghProp = ghProp:BUFFER-FIELD('{1}':U) /* pick up the handle to */
                                           /* the slot for the prop in */
                                           /* that table */
     {2} = ghProp:BUFFER-VALUE.            /* and finally set the variable */
                                           /* with contents of that slot */  
  &ELSE                                    /* but no xp macro defined */
    {2} = DYNAMIC-FUNCTION(                /* set the var by building */
           "get{1}":U IN {3}).             /* and firing a call to the */
                                           /* ordinary function */ 
  &ENDIF                                   /* end if-xp-macro-defined */
&ENDIF                                     /* end if-no-handle-passed-in */
Figure 1–2: Commented source code of GET pseudo-function