PBDR.COM

About   -   Contact   -   Purchase   -   Search   -   What's New

 
 
Check Inheritance
This tip was submitted by Prasit Sengupta.

Many a time we need to know whether an object belongs to a standard object hierarchy or not. For example, we may have a function call to be made on an object using Function Dynamic, but it should only execute if the object is inherited in a standard class hierarchy.

The following piece of code allows one to determine this:

My code uses the following ancestry for datawindows:

  • u_dwa (Highest level datawindow ancestor object)
  • u_dw_s_maint (Next level datawindow object to handle single record - freeform - maintenances)
  • u_dw_m_maint (Next level datawindow object to handle multiple record - tabular/grid - maintenances)

UO Function Name: uf_is_this_an_inherited_object

Args: apo of type PowerObject

Valid Returns: TRUE/FALSE, TRUE means that the object is inherited, FALSE means that the object is not inherited FALSE also may indicate that the object does not exist

Standard Call: uf_is_this_an_inherited_object (dw_header)

ClassDefinition lcd
Boolean lb_found

IF NOT IsValid (apo) THEN RETURN FALSE

CHOOSE CASE TypeOf (apo)
   CASE DataWindow!
      lcd = apo.ClassDefinition
      DO WHILE TRUE
         IF NOT IsValid (lcd.Ancestor) THEN EXIT
         lcd = lcd.Ancestor
         IF NOT IsValid (lcd) THEN EXIT
         IF IsValid (lcd) THEN 
            IF lcd.IsSystemType THEN EXIT
            CHOOSE CASE lower(lcd.Name)
               CASE 'u_dwa', 'u_dw_s_maint', 'u_dw_m_maint'
                  lb_found = TRUE
                  EXIT
               CASE 'powerobject'
                  //The highest level in the ancestry has been reached
                  EXIT
               CASE ELSE
                  //Do nothing
            END CHOOSE
         END IF
      LOOP	
   CASE ELSE
      //Not handled currently
END CHOOSE

RETURN lb_found

Editors Note: A great way to expand on this function would be to create an auto instantiate non visual object with a function very similar to this function only it would also accept a parameter of the class name to check for, then whenever you needed to check if an object was inherited from a base type ancestor you could call the function.

 

Top of Page

Legal Notice

Ken Howe 2011