rawhide
asked on
Objects Properties
How can i query an object for it's properties? for example: i want to find out if an object has a font property and if so do something with it.
A very nifty way to enumerate Control and object properties from Visual Basic is described in the magazine VBPJ (Visual basic Programmer's Journal) Vol 8 No 8 (July 1998). The article describes it in detail. If you can get hold of that issue, you'll get a full grip of what it entails.
In the meantime, why not try the following function :
Function HasFont(ByRef X As Control) As Boolean
On Local Error Resume Next
Dim Z As Variant
Err = 0
Z = X.Font
If Err = 0 Then
HasFont = True
Else
HasFont = False
End If
End Function
In the meantime, why not try the following function :
Function HasFont(ByRef X As Control) As Boolean
On Local Error Resume Next
Dim Z As Variant
Err = 0
Z = X.Font
If Err = 0 Then
HasFont = True
Else
HasFont = False
End If
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you make a reference to the tlbinf32.dll, which is the TypeLib Information DLL. The following code will accept a generic object & add it's properties to a listbox. Hope this helps...
Public Function DescribeObject(obj As Object) As String
Dim TLI As TLIApplication
Dim Interface As InterfaceInfo
Dim Member As MemberInfo
Set TLI = New TLIApplication
TLI.ResolveAliases = False
Set Interface = TLI.InterfaceInfoFromObjec t(obj)
Result = ""
AddText "Class: " & TypeName(obj)
AddText "GUID: " & Interface.Guid
AddText "Members: "
For Each Member In Interface.Members
With Member
If (.InvokeKind = INVOKE_PROPERTYGET Or .InvokeKind = INVOKE_UNKNOWN) And .Parameters.Count = 0 And Left(.Name, 1) <> "_" Then
'if it's not an object
If .ReturnType.TypeInfo Is Nothing Then
On Error Resume Next
AddText .Name & "=" & TLI.InvokeHook(obj, .MemberId, INVOKE_PROPERTYGET)
If Err.Number <> 0 Then
AddText .Name & "=<Unknown>"
End If
On Error GoTo 0
End If
End If
End With
Next
DescribeObject = Result
End Function
Public Sub SetMember(obj As Object, MemberName As String, NewValue As Variant)
Dim TLI As New TLIApplication
If IsObject(NewValue) Then
Call TLI.InvokeHook(obj, MemberName, INVOKE_PROPERTYPUTREF, NewValue)
Else
Call TLI.InvokeHook(obj, MemberName, INVOKE_PROPERTYPUT, NewValue)
End If
End Sub
public Sub AddText(StringToAdd As String)
Result = Result & StringToAdd & vbCrLf
End Sub
Public Function DescribeObject(obj As Object) As String
Dim TLI As TLIApplication
Dim Interface As InterfaceInfo
Dim Member As MemberInfo
Set TLI = New TLIApplication
TLI.ResolveAliases = False
Set Interface = TLI.InterfaceInfoFromObjec
Result = ""
AddText "Class: " & TypeName(obj)
AddText "GUID: " & Interface.Guid
AddText "Members: "
For Each Member In Interface.Members
With Member
If (.InvokeKind = INVOKE_PROPERTYGET Or .InvokeKind = INVOKE_UNKNOWN) And .Parameters.Count = 0 And Left(.Name, 1) <> "_" Then
'if it's not an object
If .ReturnType.TypeInfo Is Nothing Then
On Error Resume Next
AddText .Name & "=" & TLI.InvokeHook(obj, .MemberId, INVOKE_PROPERTYGET)
If Err.Number <> 0 Then
AddText .Name & "=<Unknown>"
End If
On Error GoTo 0
End If
End If
End With
Next
DescribeObject = Result
End Function
Public Sub SetMember(obj As Object, MemberName As String, NewValue As Variant)
Dim TLI As New TLIApplication
If IsObject(NewValue) Then
Call TLI.InvokeHook(obj, MemberName, INVOKE_PROPERTYPUTREF, NewValue)
Else
Call TLI.InvokeHook(obj, MemberName, INVOKE_PROPERTYPUT, NewValue)
End If
End Sub
public Sub AddText(StringToAdd As String)
Result = Result & StringToAdd & vbCrLf
End Sub
ASKER
Thanx, the article describes using C++ which not an option. I had already thought of using what you described in your answer. brian_andrews answer is exactly what i was looking for. Thanks brian.
One problem....it looks like the accepted answer was stefanx. Did you accept my answer or his??
you can change the font type, size etc from the properties controls windows
it can be found in view menu