Function Pointer as a Field

BlitzMax Forums/BlitzMax Programming/Function Pointer as a Field

Torrente(Posted 2007) [#1]
I am creating a custom Button class, and I would like to be able to define a unique function for each button that it will call when it's clicked. Is this doable using a function pointer as a field of the type? If so, anyone have an example?

I tried implementing this earlier, but it didn't seem to work.

Thanks


Torrente(Posted 2007) [#2]
Nevermind. I was just being a fool. I've spent hours and hours looking at this code, and it ends up being a rather dumb mistake.

Too bad there isn't a "delete topic" link.


Jake L.(Posted 2007) [#3]
;))) Found this thread using the forum's search?
Well, here we are:
Type FuncPointerType
  Field Callback(foo%)

  Method Trigger()
     If Callback<>Null Then Callback(42)
  End Method
End Type

Function MyFunction(i%)
 Print "The answer is "+i
End Function

Global test:FuncPointerType=New FuncPointerType
test.Callback=MyFunction
test.Trigger()



Torrente(Posted 2007) [#4]
Thanks Jake. I found the solution a few minutes after I asked for help. My problem was on the user end: I made a rather foolish mistake. Thanks though!