Accessing the data of an attribute held in a group

To find the value of an attribute in a group, you need to determine whether the attribute exists, coerce it to the right type, and call its specific protocol to access its data. This example uses the groups and attributes defined above.

The attribute subsystem requires that all attributes with the same name (and category) always be of a single class. This means that once you locate an attribute, it might be immediately coerced to this class with no further checks. The attribute framework itself does not maintain this restriction. It is up to you, although the attribute framework does provide some assistance. Attribute names and categories each default to the class name, so if none of the attributes you use override both GetName and GetCategory, this restriction is maintained.

      // You get an an attribute by providing one with the same name.
      TOneAttribute sampleAttribute;
      TAttribute* anAttribute = aGroup.Member(sampleAttribute);
      if (anAttribute) {
              // No additional check required before cast.
              sampleAttribute = *(TOneAttribute*)anAttribute;
      
              // Use protocol specific to the attribute to access it.
              TStandardText someText(*sampleAttribute.GetTextData());
          }
      }

[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker