2.3 Self-referential object models

Self-referential object models

When you start digging around the Office object models, it can be a little confusing (okay, very confusing!). You find that one object has a property that s a reference to a collection of another sort of object, or maybe it s a reference to another object. The property frequently (but not always) has the same name as the collection or other object. When you re digging in Help, it sometimes takes two or three jumps to get to something useful.

Here s an example. Say you start on Word s object model diagram and click on the Documents collection. That takes you to the Help page for the Documents collection (shown in Figure 2 look behind the dialog). What you re probably interested in, though, is the Document object, not the collection, so on the Documents page, you click on Document. That brings you to the Help page for Document. From there, you may decide to find out about the Paragraphs property, so you click Properties. Figure 10 shows the Document page and the resulting dialog.

Figure 10. From Document to Paragraphs. Many objects have properties that reference collections, using the same name as the collection. While this makes sense, it can make getting help a little long-winded, especially since often, we re ultimately headed for the individual property, not the collection.

Choosing the Paragraphs property from the dialog brings up Help for that property, as shown in Figure 11. To get to Help for the Paragraphs collection requires a click on Paragraphs; to get to the actual Paragraph object usually our actual destination requires yet another click once we get to Paragraphs. (The See Also for the Paragraphs property does actually offer a direct jump to Paragraph, but to find that out, you d have to click on See Also.) This is one of our least favorite things about the VBA Help system. We wish it were smart enough to offer some kind of consolidated help for the property and collection.

Figure 11. Not so helpful. This Help entry and others like it, while accurate, add an extra step when you re navigating from one object to another in the Help system.

There s a flip side to the issue of same-named properties and collections/objects. In some situations, the properties that access the collections or other objects don t have the same names as their targets. For example, a number of objects reference Word s ParagraphFormat object through a property named Format. Since the reference properties almost always use the object names, watch out for the special cases.

 

Copyright 2000 by Tamar E. Granor and Della Martin All Rights Reserved



Microsoft Office Automation with Visual FoxPro
Microsoft Office Automation with Visual FoxPro
ISBN: 0965509303
EAN: 2147483647
Year: 2000
Pages: 128

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net