ObjName
返回对象的名称或接口描述
ObjName ( $Objectvariable [, Flag = 1] )
参数
$Objectvariable
|
包含对象名称的变量
|
Flag
|
[可选]
$OBJ_NAME (1) = (默认) 对象名称
$OBJ_STRING (2) = 对象描述字符串
$OBJ_PROGID (3) = 对象的 ProgID(程序标识符)
$OBJ_FILE (4) = 注册表中的对象关联文件
$OBJ_MODULE (5) = 运行的对象模块名称(WIN XP 极其更高版本). Marshaller 不是 inproc 对象
$OBJ_CLSID (6) = 对象的类 CLSID
$OBJ_IID (7) = 对象的接口 ID
常量定义在 "AutoItConstants.au3"
|
返回值
成功:
|
返回名称字符串
|
失败:
|
返回 ""(空字符串), @error 设置 为非 0 值.
|
备注
不是全部对象都支持标志 2 到 7, 必需总是为这些情况测试 @error.
相关
IsObj, ObjCreate, ObjGet
函数示例
示例 1
#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
Local $oInternet = ObjCreate("InternetExplorer.Application")
$oInternet.Navigate("http://www.google.com") ; Opening a web page that contains a form
Sleep(4000) ; Give the page time to load
Local $oDoc = $oInternet.Document ; Example object to test
Local $oForm = $oDoc.Forms(0) ; Example object to test
MsgBox($MB_SYSTEMMODAL, "", "Interface name of $oInternet is: " & ObjName($oInternet) & @CRLF & _
"Object name of $oInternet is: " & ObjName($oInternet, $OBJ_STRING) & @CRLF & _
"Interface name of $oDoc is: " & ObjName($oDoc) & @CRLF & _
"Object name of $oDoc is: " & ObjName($oDoc, $OBJ_STRING) & @CRLF & _
"Interface name of $oForm is: " & ObjName($oForm) & @CRLF & _
"Object name of $oForm is: " & ObjName($oForm, $OBJ_STRING))
$oInternet.Quit()
示例 2
#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
Local $oObj = ObjCreate("InternetExplorer.Application")
ObjName_FlagsValue($oObj)
Func ObjName_FlagsValue(ByRef $oObj)
Local $sInfo = ''
$sInfo &= '+>' & @TAB & 'ObjName($oObj,1) {The name of the Object} =' & @CRLF & @TAB & ObjName($oObj, $OBJ_NAME) & @CRLF
; HELPFILE REMARKS: Not all Objects support flags 2 to 7. Always test for @error in these cases.
$sInfo &= '+>' & @TAB & 'ObjName($oObj,2) {Description string of the Object} =' & @CRLF & @TAB & ObjName($oObj, $OBJ_STRING)
If @error Then $sInfo &= '@error = ' & @error
$sInfo &= @CRLF & @CRLF
$sInfo &= '+>' & @TAB & 'ObjName($oObj,3) {The ProgID of the Object} =' & @CRLF & @TAB & ObjName($oObj, $OBJ_PROGID)
If @error Then $sInfo &= '@error = ' & @error
$sInfo &= @CRLF & @CRLF
$sInfo &= '+>' & @TAB & 'ObjName($oObj,4) {The file that is associated with the object in the Registry} =' & @CRLF & @TAB & ObjName($oObj, $OBJ_FILE)
If @error Then $sInfo &= '@error = ' & @error
$sInfo &= @CRLF & @CRLF
$sInfo &= '+>' & @TAB & 'ObjName($oObj,5) {Module name in which the object runs (WIN XP And above). Marshaller for non-inproc objects.} =' & @CRLF & @TAB & ObjName($oObj, $OBJ_MODULE)
If @error Then $sInfo &= '@error = ' & @error
$sInfo &= @CRLF & @CRLF
$sInfo &= '+>' & @TAB & 'ObjName($oObj,6) {CLSID of the object''s coclass} =' & @CRLF & @TAB & ObjName($oObj, $OBJ_CLSID)
If @error Then $sInfo &= '@error = ' & @error
$sInfo &= @CRLF & @CRLF
$sInfo &= '+>' & @TAB & 'ObjName($oObj,7) {IID of the object''s interface} =' & @CRLF & @TAB & ObjName($oObj, $OBJ_IID)
If @error Then $sInfo &= '@error = ' & @error
$sInfo &= @CRLF & @CRLF
MsgBox($MB_SYSTEMMODAL, "ObjName:", $sInfo)
EndFunc ;==>ObjName_FlagsValue
----------------------------------------
|