__objAddMethod()

Template

Function

Name

__objAddMethod()

Category

API

Subcategory

Objects

Oneliner

Add a METHOD to an already existing class

Syntax

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

Arguments

<oObject> is the object to work on.

<cMethodName> is the symbol name of the new METHOD to add.

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

Returns

__objAddMethod() return a reference to <oObject>.

Description

__objAddMethod() is a low level class support function that add a new METHOD to an object. <oObject> is unchanged if a symbol with the name <cMethodName> already exist in <oObject>.

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 )       // ;)
      ? oHappy:Smile( 3 )       // *SMILE*

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

Compliance

Harbour

Files

Library is core

Seealso

__objAddInline(), __objAddData(), __objDelMethod(), __objGetMethodList(), __objGetMsgList(), __objHasMethod(), __objModMethod()

3 responses to “__objAddMethod()

  1. Pingback: Harbour Internal Functions | Viva Clipper !

  2. Pingback: Harbour Objects Functions | Viva Clipper !

  3. Pingback: Harbour RG Summary | Viva Clipper !

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.