Using shared groups

You can instantiate TAttributeGroupHandle directly. It creates a new instance of class TInternalAttributeGroup to use. Using the copy constructor or the assignment operator makes it share an existing group. The following code sample uses the attributes from the example above to show you how to create group handles that share internal groups and use batching to control change notification.

    1  // Create group handles
    2  TAttributeGroupHandle groupX;
    3  TAttributeGroupHandle groupY = groupX;
    4  //
    5  groupX.Add(oneA);
    6  groupX.BeginChanges();
    7  groupY.Add(twoB);
    8  groupX.Add(oneC); 
    9  groupY.EndChanges();
By line 3 in the code sample above, groupX and groupY share a common internal attribute group. Line 5 causes NotifyChanged to be called on both groupX and groupY. After line 6, changes made to either groupX or groupY do not cause NotifyChanged to be called. Adding B, in line 7, affects both groups. Line 8 replaces A as before; that is, for both groups. GroupX and groupY now both have attributes B and C because they share the same internal attribute group. The call on line 9 causes NotifyChanged to be called on both groupX and groupY. It would be called even if no changes had been made to either group between the BeginChanges and EndChanges calls. Note that Begin and End were called on different groups. This doesn't matter because it's the internal group that counts.

Manage the changes to a particular group in batches. When several changes are made to a group, defer the change notification until all of the changes are made. You achieve this by first calling the member function BeginChanges, then adding or removing the required attributes, and finally, calling the member function EndChanges. This results in all affected groups receiving notification when all of the changes are complete.


[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