Navigation:  Reference > Classes > TXbClass() >

TXbClass():_Parent(oParent) / :_GwstParent(oParent)

Previous pageReturn to chapter overviewNext page

Allow to specify a parent class for inheritance.

 

TXbClass():_Parent(oParent)

TXbClass():_GwstParent(oParent)

 

<oParent>

can be a character string with the parent class name or a class object

 

When you are creating a class to implement a structure you must use :   _GwstParent()

 

TXbClass():_GwstParent() without parameters means   TXbClass():_GwstParent( "gwst" )

as the first ancestor of any ot4xb structure class is gwst()

 

If you are extending an existing structure with the intention to add more members you must use

 

TXbClass():_GwstParent( cGwstParentClass ) 

 

where   <cGwstParentClass>   in the classname of the structure you are extending

 

Only 1 call to        TXbClass():_GwstParent()        are allowed into a structure definition

Multiple calls to        TXbClass():_Parent()                are allowed for multiple inheritance

 

When combining multiple inheritance with structure definition or extension TXbClass():_GwstParent()

must be the first ancestor in the chain.

 

Example:

 

// We will start creating a class to manage the POINT structure

 

function MyPoint()

   local oClsObj := ClassObject( "MyPoint" )

   local ooo

   if oClsObj != NIL 

      return oClsObj

   endif

   ooo := TXbClass():New( "MyPoint" )

   ooo:_GwstParent()

   ooo:_Member_Int32( "x" )

   ooo:_Member_Int32( "y" )

   oClsObj := ooo:Create()

   ooo:Destroy()  

return oClsObj

// ------------------------------------------

// or the just the same using ot4xb commands

// BEGIN STRUCTURE  MyPoint

//    MEMBER INT32 x

//    MEMBER INT32 y

// END STUCTURE

// ------------------------------------------

 

// Now we want to define a miscellaneous class to handle some other things

CLASS MyClass

   EXPORTED:

   INLINE CLASS METHOD initclass() ; return Self

   INLINE METHOD SayHello() ; QOut("Hello" ) ; return NIL

ENDCLASS

 

// and now we want to extend the structure to manage the entire 

// rectangle and also inherit from MyClass to provide some other 

// functionality

function MyRect()

   local oClsObj := ClassObject( "MyRect" )

   local ooo

   if oClsObj != NIL

      return oClsObj

   endif

   ooo := TXbClass():New( "MyRect" )

   ooo:_GwstParent("MyPoint")

   ooo:_Parent("MyClass")

   ooo:_Member_Int32( "cx" )

   ooo:_Member_Int32( "cy" )

   oClsObj := ooo:Create()

   ooo:Destroy()  

return oClsObj