Function_GetPtr

<< Click to Display Table of Contents >>

Navigation:  ThinBASIC Core Language > Script structure > Functions/Subs >

Function_GetPtr

 

Description

 

Returns the internal pointer of a script function or sub.

 

Syntax

 

pFun = Function_GetPtr(FunctionName)

 

Returns

 

Number: the internal pointer to a script function.

Zero if function does not exists.

 

Parameters

 

Name

Type

Optional

Meaning

FunctionName

String

No

Name of a script function

 

Remarks

 

Restrictions

 

Returned pointer is thinBasic internal pointer. It has no meaning outside thinBasic.

Do not confuse it with machine or code pointers.

 

See also

 

Call

 

Examples

 

Uses "Console"
 
Dim fPtr As Long
Dim sPtr As Long
Dim t1, t2 As Double
 
'---Returns the internal pointer of a script function
fPtr = Function_GetPtr(MyFunction)
'---Also possible to use string expression for function/sub name
'fPtr = Function_GetPtr("My" & "Function")
 
sPtr = Function_GetPtr(MySub)
 
t1 = Timer
'---Use CALL to call using  a sub/function pointer
For Counter As Long = 1 To 10000
  Call fPtr("Hi there" & Counter)
  Call sPtr("Hi there" & Counter)
Next
t2 = Timer
 
PrintL Format$(T2 - T1, "#0.000") & " seconds"
WaitKey
 
'---Test function
Function MyFunction(Optional ByVal sMsg As StringAs Long
  Local s As String
  s = sMsg
End Function
 
'---Test sub
Sub MySub(Optional ByVal sMsg As String)
  Local s As String
  s = sMsg
End Sub