[futurebasic] Re: Function Pointers

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : May 1998 : Group Archive : Group : All Groups

From: Rick Brown <rbrown@...>
Date: Mon, 25 May 1998 09:55:36 -0500
Forrest wrote:
> I want to pass the toolbox function "FN TRACKCONTROL" a pointer to my
> procedure to handle a scrollbar click. How do you get a pointer to a
> function?

There are two ways to get a pointer to FB code, and they're used for two
different purposes.

One way is to use "@FN".  This gives you a pointer to a LOCAL FN.  For
example:

  theFNAddress& = @FN myLocalFunction

This way will _not_ work for what you have in mind.  Its purpose is to
allow you to call a LOCAL FN by means of the FN USING statement.  If you
pass theFNAddress& to FN TRACKCONTROL it won't work, because FN
TRACKCONTROL expects your procedure to follow the "Pascal calling
convention," and FB LOCAL FN's don't follow that convention.

So what you do instead is: use an ENTERPROC procedure, which _does_
follow the Pascal calling convention.  To get a pointer to an ENTERPROC
procedure, first you precede the ENTERPROC statement with a label, like
this:

"myProc"
ENTERPROC(theControl&,thePart%)
  ' Procedure code goes here
EXITPROC

Then you can use the LINE function to get a pointer to the procedure,
like so:

theProcAddress& = LINE "myProc"

This is the address that you should pass to FN TRACKCONTROL.

- Rick