Page 1 of 1

How to call a procedure via its address?

Posted: Wed Dec 03, 2008 8:44 pm
by ale870
Hello,

I need to store some procedure addreses in an array, then I need to call it using its address. Example:

Code: Select all

dim address(10)
address(0) = @myProc1()
address(1) = @myProc2()
address(2) = @myProc3()
address(3) = @myProc4()

call proc(address(1)) ; <== just for example!!!
Last line is dummy, since I don't know the real syntax.

How can I do it?

Thank you for your help!

Posted: Wed Dec 03, 2008 8:48 pm
by Heathen
CallFunctionFast()

Posted: Wed Dec 03, 2008 8:51 pm
by Comtois
prototype

Code: Select all

Prototype toto(a,b,c=4)

Define Truc.toto

Declare Bidule(a,b,c)
Truc=@Bidule()

Debug Truc(3,5)
Debug Truc(3,5,6)

Procedure Bidule(a,b,c)
  ProcedureReturn a+b+c
EndProcedure
Using CallFunctionFast

Code: Select all

Declare MyProc1(a,b)
Declare MyProc2(a,b)

Dim Address(1)
Address(0)=@MyProc1()
Address(1)=@MyProc2()   

Procedure MyProc1(a,b)
  ProcedureReturn a+b
EndProcedure

Procedure MyProc2(a,b)
  ProcedureReturn a*b
EndProcedure

For i=0 To 1
  Debug CallFunctionFast(Address(i),2,5)
Next i 
using prototype

Code: Select all

Declare MyProc1(a,b)
Declare MyProc2(a,b)

Prototype Toto(a,b)

Define Truc.toto
Dim Address(1)
Address(0)=@MyProc1()
Address(1)=@MyProc2()   
Procedure MyProc1(a,b)
  ProcedureReturn a+b
EndProcedure

Procedure MyProc2(a,b)
  ProcedureReturn a*b
EndProcedure

For i=0 To 1
  Truc=Address(i)
  Debug Truc(2,5)
Next i 

Posted: Wed Dec 03, 2008 10:28 pm
by ale870
Simply wonderful!
This is really what I was looking for!

Thank you to everyone!!! :D

Posted: Thu Dec 04, 2008 12:23 am
by pdwyer
@Comtois Nice! clear and concise! :D