Page 1 of 1

Calling a function pointer stored as a structure field?

Posted: Fri Dec 13, 2024 5:26 am
by Quin
I have a structure that stores a callback pointer on it, but I can't figure out how to actually call it. This seems like something that should be trivial, but including the parens says garbage at the end of the line. Removing them says syntax error.

Code: Select all

EnableExplicit

Structure Test
Name.s
*Callback
EndStructure

Procedure TestProc()
MessageRequester("This is a", "Test")
EndProcedure

Global T.Test
t\Name = "Test"
T\Callback = @TestProc()
T\Callback()

Re: Calling a function pointer stored as a structure field?

Posted: Fri Dec 13, 2024 6:31 am
by STARGÅTE
You have to use Prototype:

Code: Select all

EnableExplicit

Prototype TestProc()

Structure Test
Name.s
*Callback.TestProc
EndStructure

Procedure TestProc()
MessageRequester("This is a", "Test")
EndProcedure

Global T.Test
t\Name = "Test"
T\Callback = @TestProc()
T\Callback()

Re: Calling a function pointer stored as a structure field?

Posted: Fri Dec 13, 2024 6:34 am
by Quin
STARGÅTE wrote: Fri Dec 13, 2024 6:31 am You have to use Prototype:

Code: Select all

EnableExplicit

Prototype TestProc()

Structure Test
Name.s
*Callback.TestProc
EndStructure

Procedure TestProc()
MessageRequester("This is a", "Test")
EndProcedure

Global T.Test
t\Name = "Test"
T\Callback = @TestProc()
T\Callback()
Ah, makes sense. It all works, thanks! :)