HBClass()

HBClass()

HBClass() is used in the creation of all classes

Syntax

      oClass := HBClass():New("TMyClass")

        -or-

      HBClass() is usually accessed by defining a class with the commands
      defined in hbclass.h:

        CLASS HBGetList    // Calls HBClass() to create the HBGetList class
           ...
        ENDCLASS

Returns

An instance of the HBClass Class. This special object’s :New() method can then create the classes you define.

Description

HBClass is a class that … The class methods are as follows:

New() Create a new instance of the class

Examples

      FUNCTION TestObject()
         LOCAL oObject

         oObject := HBClass():New( "TMyClass" )
         oObject:End()

         RETURN NIL

Compliance

Object Oriented syntax in Harbour is compatible with CA-Cl*pper.

However CA-Cl*pper only allowed creation of objects from a few standard classes, and did not let the programmer create new classes.

In Harbour, you can create your own classes–complete with Methods, Instance Variables, Class Variables and Inheritance. Entire applications can be designed and coded in Object Oriented style.

Platforms

All

Files

Library is core

Seealso

__objHasData(), Object Oriented Programming, CLASS

__objHasMethod()

Template

Function

Name

__objHasMethod()

Category

API

Subcategory

Objects

Oneliner

Determine whether a symbol exist in object as METHOD

Syntax

      __objHasMethod( <oObject>,  <cSymbol> ) --> lExist

Arguments

<oObject> is an object to scan.

<cSymbol> is the name of the symbol to look for.

Returns

__objHasMethod() return .T. if the given <cSymbol> exist as METHOD (class function) in object <oObject), .F. if it does not exist.

Description

__objHasMethod() is a low level class support function that let you find out if a symbol is a class function in a given object.

Examples

      oB := TBrowseNew( 0,  0,  24,  79 )
      ? __objHasMethod( oB,  "nLeft" )      // .F. since this is a VAR
      ? __objHasMethod( oB,  "FixBugs" )    // hopefully this should be .F.
      ? __objHasMethod( oB,  "Left" )       // this should return .T.

Compliance

Harbour

Files

Library is core

Seealso

__objGetMethodList(), __objGetMsgList(), __objHasData()

__objGetValueList()

Template

Function

Name

__objGetValueList()

Category

API

Subcategory

Objects

Oneliner

Return an array of VAR names and values for a given object

Syntax

      __objGetValueList( <oObject>,  [<aExcept>] ) --> aData

Arguments

<oObject> is an object to scan.

<aExcept> is an optional array with VAR names you want to exclude from the scan.

Returns

__objGetValueList() return a 2D array that contain pairs of a VAR symbol name and the value of VAR. __objGetValueList() would return an empty array {} if the given object does not contain the requested information.

Description

__objGetValueList() is a low level class support function that return an array with VAR names and value, each array element is a pair of: aData[ i, HB_OO_DATA_SYMBOL ] contain the symbol name aData[ i, HB_OO_DATA_VALUE ] contain the value of DATA

Examples

      // show information about TBrowse class
      oB := TBrowseNew( 0,  0,  24,  79 )
      aData := __objGetValueList( oB )
      FOR i := 1 TO Len( aData )
         ? "VAR name:",  aData[ i,  HB_OO_DATA_SYMBOL ],  ;
            "   value=",  aData[ i,  HB_OO_DATA_VALUE  ]
      NEXT

Compliance

Harbour

Files

Header file is hboo.ch
Library is core

Seealso

__objGetMethodList(), __objGetMsgList(), __objHasData(), __objHasMethod(), __objSetValueList()

__objGetMsgList()

Template

Function

Name

__objGetMsgList()

Category

API

Subcategory

Objects

Oneliner

Return names of all VAR or METHOD for a given object

Syntax

      __objGetMsgList( <oObject>,  [<lData>],  [nClassType] ) --> aNames

Arguments

<oObject> is an object to scan.

<lData> is an optional logical value that specifies the information to return. A value of .T. instruct the function to return list of all VAR names, .F. return list of all METHOD names. Default value is .T.

<nClassType> is on optional numeric code for selecting which class type to return. Default value is HB_MSGLISTALL, returning the whole list.

Returns

__objGetMsgList() return an array of character stings with all VAR names or all METHOD names for a given object. __objGetMsgList() would return an empty array {} if the given object does not contain the requested information.

Description

__objGetMsgList() is a low level class support function that let you find all instance variable or method names for a given object.

If specified, the following table shows the values for <nClassType> that allow you to distinguish between VAR and CLASS VAR:

      hboo.ch           Value   Meaning
      ----------------  -----   -----------------
      HB_MSGLISTALL     0       All types
      HB_MSGLISTCLASS   1       CLASS VAR only
      HB_MSGLISTPURE    2       VAR only

VAR are instance variable usable within each object from a class, where each object has its own VARs.

CLASS VAR are shared by all objects from a Class, so the changed value within Object1 will be reflected when accessing the CLASS VAR from Object2.

Examples

      // show information about TBrowse class
      oB := TBrowseNew( 0,  0,  24,  79 )
      aData      := __objGetMsgList( oB,  .T. )
      aClassData := __objGetMsgList( oB,  .T.,  HB_MSGLISTCLASS )
      aMethod    := __objGetMsgList( oB,  .F. )
      FOR i := 1 TO Len( aData )
         ? "VAR name:",  aData[ i ]
      NEXT
      FOR i := 1 TO Len( aClassData )
         ? "CLASS VAR name:",  aClassData[ i ]
      NEXT
      FOR i := 1 TO Len( aMethod )
         ? "METHOD name:",  aMethod[ i ]
      NEXT

Compliance

Harbour

Files

Header file is hboo.ch
Library is core

Seealso

__objGetMethodList(), __objGetValueList(), __objHasData(), __objHasMethod()

__objGetMethodList()

Template

Function

Name

__objGetMethodList()

Category

API

Subcategory

Objects

Oneliner

Return names of all METHOD for a given object

Syntax

      __objGetMethodList( <oObject> ) --> aMethodNames

Arguments

<oObject> is an object to scan.

Returns

__objGetMethodList() return an array of character stings with all METHOD names for a given object. __objGetMethodList() would return an empty array {} if the given object does not contain any METHOD.

Description

__objGetMethodList() is a low level class support function that let you find all class functions names for a given object. It is equivalent to __objGetMsgList(oObject, .F.).

Examples

      // show information about TBrowse class
      oB := TBrowseNew( 0,  0,  24,  79 )
      aMethod := __objGetMethodList( oB )
      FOR i := 1 TO Len( aMethod )
         ? "METHOD name:",  aMethod[ i ]
      NEXT

Compliance

Harbour

Files

Library is core

Seealso

__objGetMsgList(), __objGetValueList(), __objHasData(), __objHasMethod()

__objDerivedFrom()

Template

Function

Name

__objDerivedFrom()

Category

API

Subcategory

Objects

Oneliner

Determine whether a class is derived from another class

Syntax

      __objDerivedFrom( <oObject>,  <xSuper> ) --> lIsParent

Arguments

<oObject> is the object to check.

<xSuper> is the object that may be a parent. <xSuper> can be either an Object or a Character string with the class name.

Returns

__objDerivedFrom() return a logical TRUE (.T.) if <oObject> is derived from <xSuper>.

Description

__objDerivedFrom() is a low level class support function that check is one class is a super class of the other, or in other words, does class <oObject> a child or descendant of <xSuper>.

Examples

      // Create three classes and check their relations

      #include "hbclass.ch"
      PROCEDURE Main()
         LOCAL oSuper,  oObject,  oDress
         oSuper  := TMood():New()
         oObject := THappy():New()
         oDress  := TShirt():New()
         ? __objDerivedFrom( oObject,  oSuper )    // .T.
         ? __objDerivedFrom( oSuper,  oObject )    // .F.
         ? __objDerivedFrom( oObject,  oDress )    // .F.
         RETURN

      CREATE CLASS TMood
         METHOD New() INLINE Self
      ENDCLASS

      CREATE CLASS THappy FROM TMood
         METHOD Smile() INLINE QOut( "*smile*" )
      ENDCLASS

      CREATE CLASS TShirt
         VAR Color
         VAR Size
         METHOD New() INLINE Self
      ENDCLASS

Compliance

Harbour

Files

Library is core

Seealso

__objHasData(), __objHasMethod()

__objDelData()

Template

Function

Name

__objDelData()

Category

API

Subcategory

Objects

Oneliner

Delete a VAR (instance variable) from class

Syntax

      __objDelMethod( <oObject>,  <cDataName> ) --> oObject

Arguments

<oObject> is the object to work on.

<cDataName> is the symbol name of VAR to be deleted (removed) from
the object.

Returns

__objDelData() return a reference to <oObject>.

Description

__objDelData() is a low level class support function that delete (remove) a VAR from an object. <oObject> is unchanged if a symbol with the name <cDataName> does not exist in <oObject>.

Examples

      // create a new THappy class and add a lHappy VAR
      oHappy  := HBClass():New( "THappy" )
      __objAddData( oHappy,  "lHappy" )
      ? __objHasData( oHappy,  "lHappy" )    // .T.
      // remove lHappy VAR
      __objDelData( oHappy,  "lHappy" )
      ? __objHasData( oHappy,  "lHappy" )    // .F.

Compliance

Harbour

Files

Library is core

Seealso

__objAddData(), __objGetMsgList(), __objGetValueList(), __objHasData(), __objSetValueList()