How to pass a method into a function
BlitzMax Forums/BlitzMax Programming/How to pass a method into a function
| ||
please consider this code:Strict Type Ta Method b() End Method Function c() End Function End Type Local a:Ta = New Ta test(a.b) test(Ta.c) Function test(z()) Print "something" End Function It won't compile because it won't let me pass a method b() into the test function. If you comment out the duff line, the function c() can be passed in fine. Don't suppose there's another way to do this apart from turning my method into a function and putting "self." in front of anything important? |
| ||
test(a.b()) should do it...? I use Superstrict and this forces me to have the return type declared with the method: Method B:ReturnType() End Method ... test(a.b()) |
| ||
No method pointers in Max. Turn it into a func or wrap it in a func to do this.l |
| ||
Or wait for the changes mark mentions in his worklog as the reflection feature should actually allow that (he points that out with his pseudo delegate part as well) |
| ||
You could implement a SendMessage() method that all types have anyway and have the function call it. Its not the same thing but can be used similiar: Strict Type Ta Method SendMessage:Object( message:Object,sender:Object ) If String(message)="b" Print "the message is b" ElseIf String(message)="c" Print "the message is c" Else Print "unknown message" EndIf EndMethod End Type Local a:Ta = New Ta test(a,"b") test(a,"c") test(a,"x") Function test(z:Object,s:String) z.SendMessage(s,Null) Print "something" End Function |
| ||
No method pointers in Max. Turn it into a func or wrap it in a func to do this. suspected as much.Thanks all. Azathoth: thanks. Yeah I wanted to pass in the method so I could actually call it. That much wasn't clear in my example. |