OWBasic for Pocketviewer

Home INTRO Group POINTERS Alphabetical Index

Function and procedure pointers

OWBasic allows the declaration of global variables that point to functions or procedures.
Before a function pointer can be used, it has to be declared:

DIM <name>~(PROC <paramlist>)[<size>]
DIM <name>~(FUNC<return type> <paramlist>)[<size>]

<paramlist> gives the parameter types of the function/procedure:

[VAR] <type suffix> [[]], ...

A function pointer can be assigned a value like any other variable; the address of a procedure or a function can be requested with

PROC(<procedure name>)
FUNC(<function name>)

It is possible to assign the symbolic value #NULL to a function pointer and do convert it to integer for checking whether the pointer is NULL.
A function or procedure pointer is called by the directive CALL:

CALL <procptrname> <parameters>
CALL <type suffix> (<funcptrname> <parameters>)

Example:

DIM screeninit~(PROC)[0]
DIM bname~(FUNC$ %)[0]

PROC drawscreen
IF INT(screeninit)<>0 THEN
 CALL screeninit
ENDIF
TEXTBOX CALL$(bname RND(2)),10,30,149,40,0
ENDP

FUNC name$ n
RETURN "Nr. "+STRING(n)

PROC init
CLS 2
BOX 0,0,159,159
ENDP

screeninit=PROC(init)
bname=FUNC(name$)

drawscreen

Home INTRO Group POINTERS Alphabetical Index