Revision [22339]

This is an old revision of KeyPgSubPtr made by JeffMarshall on 2018-06-28 10:46:14.


SUB Pointer

Data type that stores a pointer to a SUB procedure

dim variable as Sub [CDecl|Pascal|StdCall] [( [parameter_list] )] [= initializer]

parameter_list: parameter[, parameter[, ...]]
parameter: [ByRef|ByVal] identifier [As type] [= default_value]
identifier: the name of the variable referenced in the subroutine
type: the type of variable
default_value: the value of the argument if none is specified in the call
intializer: address of a subroutine to set as the intial value

A Sub pointer is a procedure pointer that stores the memory location of compiled code. If no intializer is given the default initial value is zero (0).

The memory address for the Sub procedure can be assigned to the variable by taking the address of a subroutine with ProcPtr or Operator @ (Address of).

The procedure must match the same Sub declaration as the declared Sub pointer.

To call the subroutine assigned, use the variable name as if it were a normal declared Sub.

    Sub Hello()
        Print "Hello"
    End Sub

    Sub Goodbye()
        Print "Goodbye"
    End Sub

    Dim x As Sub() = ProcPtr( Hello )


    x = @Goodbye  '' or procptr(Goodbye)


Differences from QB:
See also:
Back to Standard Data Types

Valid XHTML :: Valid CSS: :: Powered by WikkaWiki phatcode