85 of 158
79 Dim Volatile addr as Integer Dim bv as Byte Based addr.DataAddress When defining an array variable that is Based, you may omit the <dim-list> element. In this case, the compiler will assume that the array is one-dimensional, that its lower bound is 1 and that its upper bound is a large value. Dim addr as UnsignedInteger Dim ba() as Byte Based addr It is also permissible to define a based Persistent Memory or Program Memory variable. This is accomplished by using the normal syntax for defining a persistent/program memory variable and appending the Based keyword and address expression. Dim persVar as Persistent Integer Based &H300 Dim progVar as ProgMem Single Based &H1000 BasicX Compatibility Note Based variables are not available in BasicX compatibility mode. 3.23 Based Procedures Like based variables, based procedures are a powerful tool intended to be used by advanced programmers who fully understand their nuances. No actual code space is consumed by a based procedure. Rather, declaring a based procedure simply tells the compiler how to generate an invocation of the procedure once its address is known. The syntax for declaring a based subroutine or based function is shown below. Delare Sub <name> ( [<parameter-list>] ) Based <addr-expr> Declare Function <name> ( [<parameter-list>] ) As <type> Based <addr-expr> As with based variables, the <addr-expr> giving the address of the procedure to be invoked must have an integral type and can be either constant or non-constant (i.e., computed at run time). The based procedure declaration may be placed inside a subroutine or function in which case the declaration is private to that routine. At the module level, the Declare keyword may be proceeded by Public or Private and if neither is specified, the declaration will be public by default. When using a based procedure, you must be very careful to be certain that the declaration matches the actual procedure that exists at the address that is specified. If the address given is not the beginning of a procedure that is the same type and has the same number and type of parameters, the result is unpredictable but will likely cause your program to malfunction. BasicX Compatibility Note Based proceduresles are not available in BasicX compatibility mode.