[Gambas-user] Callback

Jussi Lahtinen jussi.lahtinen at ...626...
Thu Aug 11 22:03:21 CEST 2011


Or, see code:

To class named "Twotimes":

Static Public Function _call(x As Integer) As Integer
  Return x * 2
End


Then somewhere else:

''This is the function that accepts callbacks.
Public Function testing(x As Integer, ofunc As Object) As Integer
 Return ofunc(x)
End


''Here is how to call it.
Dim ChosenFunction As Object

ChosenFunction = New Twotimes ''Here you can set the callback function.
Print testing(2, ChosenFunction)


Jussi




2011/8/11 Benoît Minisini <gambas at ...1...>

> > hi,
> >
> > i wonder how one would specify a function callback to a function (i
> > haven't tried anything because nothing seems to me to work). no way with
> > a functions name as string and Class[name] because i can't get a pointer
> > to the actual symbol via this method but only to a .Symbol object. i
> > also can't call a pointer (as it would be with passing the functions
> > address) or something because it is not possible to cast a pointer to a
> > function... or do i miss something here?
> >
> > regards,
> > tobi
> >
>
> There is way to simulate callback functions by using the Object.Call()
> function, which can call any method in any object by name. But it is slower
> than a direct call.
>
> An intermediate solution is when you can agree on the function name. Then
> you
> can use inheritance, i.e. you change the class, but keep the same method
> name,
> and make all these class inherit the same parent class.
>
> Regards,
>
> --
> Benoît Minisini
>
>
> ------------------------------------------------------------------------------
> Get a FREE DOWNLOAD! and learn more about uberSVN rich system,
> user administration capabilities and model configuration. Take
> the hassle out of deploying and managing Subversion and the
> tools developers use with it.
> http://p.sf.net/sfu/wandisco-dev2dev
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>



More information about the User mailing list