Page 1 of 1
How do I get a pointer to a method in a class?
Posted: Fri Jun 18, 2021 8:49 am
by huiyi_ch
Hello friends
How do I get a pointer to a method in a class?
For a function, we can return it with the following statement:
point:=@<FunctionName>()
But how do you get a pointer to a method in a class?
Re: How do I get a pointer to a method in a class?
Posted: Fri Jun 18, 2021 11:57 am
by gfilatov
huiyi_ch wrote: ↑Fri Jun 18, 2021 8:49 am
How do I get a pointer to a method in a class?
Hello,
Did you tried the function __objModMethod( oObject, cSymbol, nFuncPtr )
Please take a look for the working example below:
Code: Select all
#include "hbclass.ch"
Procedure Main()
Local oClass1, oClass2
oClass1 := Class1()
oClass2 := Class2()
__ObjAddMethod(oClass1, "Two",@Two())
__ObjAddMethod(oClass2, "Two", @Two())
oClass1:Two()
oClass2:Two()
__objModMethod(oClass2, "Two", @Three())
oClass2:Two()
Return
CLASS Class1
METHOD One BLOCK {|Self| qout("This is Method One of "+::ClassName()) }
END CLASS
CLASS Class2
METHOD One BLOCK {|Self| qout("This is Method One of "+::ClassName()) }
END CLASS
Function Two()
Local Self := QSelf()
qout("This is Function Two of "+::ClassName() )
Return ::One()
Function Three()
Local Self := QSelf()
qout("This is Function Three of "+::ClassName() )
Return Nil
Hope that helps

Re: How do I get a pointer to a method in a class?
Posted: Sat Jun 19, 2021 2:20 am
by huiyi_ch
Thank you for answer.