操作符 Procptr (程序指针)
 
返回过程的地址

语法

Declare Operator ProcPtr ( ByRef lhs As T ) As T Ptr

用法

result = ProcPtr ( lhs )

参数

lhs
一个程序。
T
程序的类型

返回值

返回过程的地址。

说明

该运算符返回SubFunction过程的地址。

操作符 @ (Address Of)与程序一起使用时,具有相同的行为。

例子

'此示例使用ProcPtr来演示函数指针
Declare Function Subtract( x As Integer, y As Integer) As Integer
Declare Function Add( x As Integer, y As Integer) As Integer
Dim myFunction As Function( x As Integer, y As Integer) As Integer

'myFunction现在将赋值给Add
myFunction = ProcPtr( Add )
Print myFunction(2, 3)

'myFunction现在将被赋值给Subtract。注意不同的输出。
myFunction = ProcPtr( Subtract )
Print myFunction(2, 3)

Function Add( x As Integer, y As Integer) As Integer
    Return x + y
End Function

Function Subtract( x As Integer, y As Integer) As Integer
    Return x - y
End Function


方言差异

  • -lang qb 方言中不可用,除非使用别名__Procptr引用。

与QB差别

  • 新的FreeBASIC

参考