Warning

 

Close
Confirm Action

Are you sure you wish to do this?

Cancel Confirm
AR15.COM
1/14/2002 11:40:21 PM EDT
This may be a long shot but I'll ask here first anyway.

Is there a way to programmatically navigate through the properties and collections on a COM object?  We have some objects we've written that represent customers in a database.  I'd like to build an XML representation of these objects once all the data has been populated, but it's a pain in the ass to have to build it all by hand, plus if we add new stuff in the future, we'd have to also make sure the XML contains the new stuff.  If there were a way to programmatically navigate through a COM object, it would handle all that for us.

So, I'd be looking for something like this:

For each Item in Customer.Properties
   code for Item.Name & Item.Value
Next

Does that make sense?
1/14/2002 11:55:41 PM EDT
[#1]
Java has a nice "reflection API" set of classes.
1/15/2002 4:54:42 AM EDT
[#2]
Don't know about the looping through properties but..

If the class is based on a database, why not make your xml off the database.

Or, it would be easy enough to code something that looked at your source code, and generated the structure based on that. You could re run it with each release
1/15/2002 5:24:43 AM EDT
[#3]
I asked my buddy who said this:

This is definitly probable, but to give you an answer from the top of my head would be difficult. Although the solution can be achieved roughly the way that you have it described I would need a snipet of your code to determine the proper sytax to use for the problem at hand.



1/15/2002 10:20:07 AM EDT
[#4]
Quoted:
If the class is based on a database, why not make your xml off the database.
View Quote


That's a possibility, though we do some business logic on the data after we get it from the database (formatting, generating URLs, etc).
1/15/2002 10:25:26 AM EDT
[#5]
Quoted:
I would need a snipet of your code to determine the proper sytax to use for the problem at hand.
View Quote


Here's what it looks like when we use this object.

Dim oCustomer as Customer, Employee as Customer.Employee

Set oCustomer = New Customer

oCustomer.LoadCustomer(123)

(At this point, the data from the database is loaded into the customer object)

Debug.Print Customer.CompanyName
Debug.Print Customer.Phone

(We also have collections)

For each Employee in Customer.Employees
  Debug.Print Employee.Name
  Debug.Print Employee.Email
Next

I'd like to be able to do the Customer.LoadCustomer, pass that through something which would let me parse the properties & collections, from which I could generate XML, such as (the formatting is going to suck):







1/15/2002 11:56:51 AM EDT
[#6]
DVD tracker:


He said:  


davisra3: Are you looking for the formatting structure or the code structure...because what you have for the For Each loop will work if you change the debug.print part to a var that excepts the value of the field being queried.
SatCong70: lemme ask him
1/15/2002 3:09:24 PM EDT
[#7]
Sorry, I don't have AIM, just ICQ and YIM.

1/15/2002 3:29:17 PM EDT
[#8]
Woot!  Found what I was looking for.  By referencing the TypeLib Information object (tlbinf32.dll), I'm able to programmatically browse an object.  Example:

   Dim oBrowse As TLI.TLIApplication, Customer As APPresentation.Customer
   Dim iInfo As TLI.InterfaceInfo, Member As TLI.MemberInfo

   
   Set oBrowse = New TLI.TLIApplication
   Set Customer = New APPresentation.Customer
   
   Set iInfo = oBrowse.InterfaceInfoFromObject(Customer)
   
   For Each Member In iInfo.Members
       Debug.Print Member.Name
   Next
   
   Set oBrowse = Nothing