如何判断任意一个控件的任意一个属性是否存在?

aikill 2003-04-25 05:40:26
比如说有aaa控件,怎么才能判断aaa控件是否存在属性bbb(不要用on error)。
...全文
84 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
rainstormmaster 2003-05-04
  • 打赏
  • 举报
回复
有收获, Intelement(智能元素) 从哪里找到的资料,有枚举方法的吗?
Intelement 2003-05-04
  • 打赏
  • 举报
回复
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_11167372.html

Search Keywords [vb check property exists]
MyLf 2003-05-03
  • 打赏
  • 举报
回复
有收获
Intelement 2003-05-03
  • 打赏
  • 举报
回复
是啊!
Agree to nik_Amis(Azrael)
右键单击 Object Browser
从弹出的快捷菜单里选择 Show Hidden Members
nik_Amis 2003-05-03
  • 打赏
  • 举报
回复
Kivic(Kivic)

??那些属性差不到?
对象浏览器还可以差到隐藏的属性

Intelement 2003-05-03
  • 打赏
  • 举报
回复
干杯吧!
兄弟们!
Intelement 2003-05-03
  • 打赏
  • 举报
回复
网上找到的资料
======================================================================
This is how you can get a list of properties for an object or determine if a property exists for an object...


1) Add the "TypeLib Information" reference to your project. To do this, click "Project->References..." then select "TypeLib Information" (TLBINF32.DLL) from the reference list.

2) Add the following code to a MODULE:

'-------------------------------------------------------------------------------
Public Enum EPType
ReadableProperties = 2
WriteableProperties = 4
End Enum
Public Function EnumerateProperties(pObject As Object, pType As EPType) As Variant
Dim rArray() As String
Dim iVal As Long
Dim TypeLib As TLI.InterfaceInfo
Dim Prop As TLI.MemberInfo
On Error Resume Next
ReDim rArray(0) As String
Set TypeLib = TLI.InterfaceInfoFromObject(pObject)
For Each Prop In TypeLib.Members
If Prop.InvokeKind = pType Then
iVal = UBound(rArray)
rArray(iVal) = UCase$(Prop.Name)
ReDim Preserve rArray(iVal + 1) As String
End If
Next
ReDim Preserve rArray(UBound(rArray) - 1) As String
EnumerateProperties = rArray
End Function
Public Function DoesPropertyExist(pObject As Object, ByVal _
PropertyName As String, pType As EPType) As Boolean
Dim Item As Variant
PropertyName = UCase$(PropertyName)
For Each Item In EnumerateProperties(pObject, pType)
If Item = PropertyName Then
DoesPropertyExist = True
Exit For
End If
Next
End Function
'-------------------------------------------------------------------------------


Then you can do something like this:

If DoesPropertyExist(Command1, "Caption", ReadableProperties) = True Then
Debug.Print "YES"
Else
Debug.Print "NO"
End If

The above example will check if the Readable property "Caption" exists for the control "Command1"... In this case it will return true...

If DoesPropertyExist(Command1, "Text", ReadableProperties) = True Then
Debug.Print "YES"
Else
Debug.Print "NO"
End If

In the above example we're checking if the "Command1" object contains the readable property "Text".... It does not, so it will return false.



Cheers!.)

======================================================================

MyLf 2003-05-03
  • 打赏
  • 举报
回复
To DeityFox:
我也想知道怎么枚举一个控件(对象)的属性。
给你留言了。
DeityFox 2003-05-03
  • 打赏
  • 举报
回复
你给我留言,告诉我email地址,我发给你例子

我不想在这里公开邮件地址
DeityFox 2003-04-30
  • 打赏
  • 举报
回复
呵呵,前天刚刚在研究这个问题,已经有解决办法

就是自己通过代码枚举所有属性,然后就可以判断某个属性存在是否
aikill 2003-04-30
  • 打赏
  • 举报
回复
怎么枚举?
lazycat818 2003-04-30
  • 打赏
  • 举报
回复
错误处理不是很好吗?为什么不用呢?
rainstormmaster 2003-04-29
  • 打赏
  • 举报
回复
帮你up,估计很困难
aikill 2003-04-29
  • 打赏
  • 举报
回复
只想知道在代码中怎么实现
frieder 2003-04-28
  • 打赏
  • 举报
回复
To Kivic(Kivic):
这种情况不大可能. 你能举个例子吗 ?
试想想, 如果有些属性不能通过查询接口查询得到结果, 那它做出来有何用呢.
可以这样说, 当你建立一个object并且dot了它, 你在快显窗口看到的就应该是它全部的属性和方法.
Kivic 2003-04-28
  • 打赏
  • 举报
回复
我不同意lihonggen0的说法,有些属性是任何浏览器都查不着的,只能凭经验,只要是对的,编译也能过去,最常见的如object属性
lihonggen0 2003-04-26
  • 打赏
  • 举报
回复
对象浏览器,可以查看所有属性,方法等

还有就是,没有这个属性的时候,编译是不能通过的.........

也就是运行不了

loveerror 2003-04-26
  • 打赏
  • 举报
回复
我覺我們用控件還是應該首先知道它有哪些屬性.一般不會用自己都不知道它有沒有的屬性的.
frieder 2003-04-25
  • 打赏
  • 举报
回复
通常情况下﹐你都会看到一个控件的所有属性(通过快显功能)。
qffhq 2003-04-25
  • 打赏
  • 举报
回复
我也想知道呀,强烈关注
qffhq@21cn.com,QQ:813700026

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧