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?
How do I get a pointer to a method in a class?
Moderator: Rathinagiri
How do I get a pointer to a method in a class?
Last edited by huiyi_ch on Fri Jun 18, 2021 12:46 pm, edited 1 time in total.
Re: 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
Kind Regards,
Grigory Filatov
"Everything should be made as simple as possible, but no simpler." Albert Einstein
Grigory Filatov
"Everything should be made as simple as possible, but no simpler." Albert Einstein
Re: How do I get a pointer to a method in a class?
Thank you for answer.