[SOLVED] Possible to pass procedure pointer as parameter?

Just starting out? Need help? Post your questions and find answers here.
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

[SOLVED] Possible to pass procedure pointer as parameter?

Post by SkyManager »

I have a question :

Is it possible to pass the pointer of a procedure as a parameter to another function/procedure so that it can be executed?

I have tried the following code,
it returns only the procedure pointer,
not running it!
How can I run a procedure after obtaining its pointer

Code: Select all

Procedure.s test()
  ProcedureReturn "test"
EndProcedure

Procedure run(ptr) ; Assume ptr is the procedure pointer
  Debug @ptr ; <----- This return only the pointer value, not executing the pointer
EndProcedure

run(@test())
Last edited by SkyManager on Thu Aug 08, 2019 6:18 am, edited 1 time in total.
User avatar
RSBasic
Moderator
Moderator
Posts: 1228
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Possible to pass procedure pointer as parameter?

Post by RSBasic »

Code: Select all

Procedure.s test()
  ProcedureReturn "test"
EndProcedure

Procedure run(ptr) ; Assume ptr is the procedure pointer
  Debug PeekS(CallFunctionFast(ptr))
EndProcedure

run(@test())
Image
Image
Little John
Addict
Addict
Posts: 4807
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Possible to pass procedure pointer as parameter?

Post by Little John »

Help for CallFunctionFast() wrote:The use of prototypes is now strongly recommended.

Code: Select all

EnableExplicit

Prototype.s ProtoTest()

Procedure.s Test1()
   ProcedureReturn "Hello from test #1"
EndProcedure

Procedure.s Test2()
   ProcedureReturn "Hello from test #2"
EndProcedure


Procedure Run(MyTest.ProtoTest)
   Debug MyTest()
EndProcedure

Run(@Test1())
Run(@Test2())
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Re: Possible to pass procedure pointer as parameter?

Post by SkyManager »

Thanks a lot :D
Post Reply