IsDeclared
检测变量是否已声明.
IsDeclared ( expression )
参数
返回值
成功:
|
返回 $DECLARED_GLOBAL (1), 变量为全局变量或由外部函数声明
|
专用:
|
返回 $DECLARED_LOCAL (-1), 变量为局部变量
|
失败:
|
返回 $DECLARED_UNKNOWN (0), 表示未发现检查的变量
|
常量定义在 AutoItConstants.au3
备注
如果需要, 使用 IsDeclared() 检查变量是否存在, 可以使用 Assign() 创建变量或写入变量值, 并使用 Eval() 读取变量.
函数示例
#include <MsgBoxConstants.au3>
; Check if the variable $vVar is declared. As the variable isn't will display the error message.
If Not IsDeclared("vVar") Then
MsgBox($MB_SYSTEMMODAL, "", "The variable $vVar is not declared.")
Local $vVar = 0 ; Initialize the variable $vVar with data.
If IsDeclared("vVar") Then ; Check if the variable $vVar is declared.
MsgBox($MB_SYSTEMMODAL, "", "The variable $vVar is declared.")
Else
MsgBox($MB_SYSTEMMODAL, "", "The variable $vVar is not declared.")
EndIf
EndIf
----------------------------------------
该函数可以通过命令 exect 调用
参见:
Assign, Eval
exect=$var_n=IsDeclared('var_s')||_ViewValues('$var_n') ;; 变量$var_n = 0,因为变量$var_s不存在
exect=$var_s='字符串'||$var_n=IsDeclared('var_s')||_ViewValues('$var_n') ;; 变量$var_n = 1,因为变量$var_s存在
© Аверин Андрей для Total Commander Image Averin-And@yandex.ru
|