Viva Clipper !

__objModMethod()

Advertisements

Template

Function

Name

__objModMethod()

Category

API

Subcategory

Objects

Oneliner

Modify (replace) a METHOD in an already existing class

Syntax

      __objModMethod( <oObject>,  <cMethodName>,  <nFuncPtr> ) --> oObject

Arguments

<oObject> is the object to work on.

<cMethodName> is the symbol name of the METHOD to modify.

<nFuncPtr> is a pointer to a new function to associate with the method.

Returns

__objModMethod() return a reference to <oObject>.

Description

__objModMethod() is a low level class support function that modify a METHOD in an object and replace it with a new function. <oObject> is unchanged if a symbol with the name <cMethodName> does not exist in <oObject>. __objModMethod() is used in inheritance mechanism.

Note that <nFuncPtr> is a special pointer to a function that was created using the @ operator, see example below.

Examples

      // create a new THappy class and add a Smile method
      oHappy := HBClass():New( "THappy" )
      __objAddMethod( oHappy,  "Smile",  @MySmile() )
      ? oHappy:Smile( 1 )       // :)
      ? oHappy:Smile( 2 )       // ;)
      // replace Smile method with a new function
      __objAddMethod( oHappy,  "Smile",  @YourSmile() )
      ? oHappy:Smile( 1 )       // *SMILE*
      ? oHappy:Smile( 2 )       // *WINK*

      STATIC FUNCTION MySmile( nType )
         LOCAL cSmile
         DO CASE
         CASE nType == 1
            cSmile := ":)"
         CASE nType == 2
            cSmile := ";)"
         ENDCASE
         RETURN cSmile

      STATIC FUNCTION YourSmile( nType )
         LOCAL cSmile
         DO CASE
         CASE nType == 1
            cSmile := "*SMILE*"
         CASE nType == 2
            cSmile := "*WINK*"
         ENDCASE
         RETURN cSmile

Compliance

Harbour

Files

Library is core

Seealso

__objAddMethod(), __objDelMethod(), __objGetMethodList(), __objGetMsgList(), __objHasMethod()

Advertisements

Advertisements