Posted: 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? |
|
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 |
|
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. |
|
Quoted: I would need a snipet of your code to determine the proper sytax to use for the problem at hand. 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): |
|
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 |
|
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 |