Call
调用用户定义函数, 或包含在第一个参数中的内置函数.
Call ( "function" [, param1 [, param2 [, paramN]]] )
参数
function
|
函数或调用函数的名称.
|
param
|
传递给调用函数的参数.
|
返回值
成功:
|
返回调用函数的返回值. @error 和 @extended 可能包含调用函数设置的值.
|
失败:
|
设置 @error 为 0xDEAD; @extended 为 0xBEEF, 表示函数不存在或参数数量无效.
|
备注
本函数可以给调用的函数传递参数, 但不支持 ByRef(引用) 参数; 没有方法来检索 ByRef(引用) 参数.
一个特殊的数组可以代替单独的参数来传递. 这个数组的第一个元素必须设置为 "CallArgArray", 元素 1 - n 将作为单独参数传递给函数. 如果使用这种特殊数组, 则不应再有其他参数传递给 Call(). 见函数示例.
Call() 本身可以设置 @error 标志或由调用函数设置 @error 标志. 如果 Call() 设置 @error 标志, 值应设置为 0xDEAD 且 @extended 也应设置为 0xBEEF. 见示例中测试未发现的函数的演示.
相关
Execute
函数示例
#include <MsgBoxConstants.au3>
Example()
Func Example()
; This calls a function accepting no arguments.
Call("Test1")
; This calls a function accepting one argument and passes it an argument.
Call("Test2", "Message from Call()!")
; This demonstrates how to use the special array argument.
Local $aArgs[4]
$aArgs[0] = "CallArgArray" ; This is required, otherwise, Call() will not recognize the array as containing arguments
$aArgs[1] = "This is a string" ; Parameter one is a string
$aArgs[2] = 47 ; Parameter two is a number
Local $aArray[2]
$aArray[0] = "Array Element 0"
$aArray[1] = "Array Element 1"
$aArgs[3] = $aArray ; Parameter three is an array
; We've built the special array, now call the function
Call("Test3", $aArgs)
; Test calling a function that does not exist. This shows the proper way to test by
; checking that both @error and @extended contain the documented failure values.
Local Const $sFunction = "DoesNotExist"
Call($sFunction)
If @error = 0xDEAD And @extended = 0xBEEF Then MsgBox($MB_SYSTEMMODAL, "", "Function does not exist.")
EndFunc ;==>Example
Func Test1()
MsgBox($MB_SYSTEMMODAL, "", "Hello")
EndFunc ;==>Test1
Func Test2($sMsg)
MsgBox($MB_SYSTEMMODAL, "", $sMsg)
EndFunc ;==>Test2
Func Test3($sString, $nNumber, $aArray)
MsgBox($MB_SYSTEMMODAL, "", "The string is: " & @CRLF & $sString)
MsgBox($MB_SYSTEMMODAL, "", "The number is: " & @CRLF & $nNumber)
For $i = 0 To UBound($aArray) - 1
MsgBox($MB_SYSTEMMODAL, "", "Array[" & $i & "] contains:" & @CRLF & $aArray[$i])
Next
EndFunc ;==>Test3
----------------------------------------
|