' Simple function pointer example for Rapid-Q by William Yu
' You can't bind to DLL functions, only local procedures.

DECLARE SUB Proc1 (I AS INTEGER)
DECLARE SUB Proc2 (I AS INTEGER)
DECLARE SUB Proc3 (I AS INTEGER)
DECLARE SUB Proc4 (I AS INTEGER)

DIM FPtr(1 TO 10) AS INTEGER  '-- Theoretically can be anything, but avoid BYTE

BIND FPtr(1) TO Proc1         '-- Bind functions
BIND FPtr(2) TO Proc2         '-- FPtr is bound, so all functions must
BIND FPtr(3) TO Proc3         '-- have matching parameters.
BIND FPtr(4) TO Proc4

DO
  PRINT "Enter a number between 1 - 4: ";
  A$ = INPUT$(1)
LOOP UNTIL VAL(A$) < 5 AND VAL(A$) > 0

CALLFUNC(FPtr(VAL(A$)), VAL(A$)^5)        '-- Call our function...

END

SUB Proc1 (I AS INTEGER)
  PRINT "Inside proc1, parameter = "; I
END SUB

SUB Proc2 (I AS INTEGER)
  PRINT "Inside proc2, parameter = "; I
END SUB

SUB Proc3 (I AS INTEGER)
  PRINT "Inside proc3, parameter = "; I
END SUB

SUB Proc4 (I AS INTEGER)
  PRINT "Inside proc4, parameter = "; I
END SUB                                
