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 using a function pointer we have to declare a function pointer type:

FPTR <typename>=(PROC <paramlist>)
FPTR <typename>=(FUNC<return type> <paramlist>)

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

[VAR] <dummy variable> [[]], ...

A function pointer is a variable, according to this it does not need to be declared (if you want to declare a function pointer, use LOCAL):

<varname>\<typename>=#NULL

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:

FPTR myproc_t=(PROC)
FPTR myfunc_t=(FUNC$ i%)

DIM screeninit\myproc_t[0]
DIM bname\myfunc_t[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