Stingray Studio : Objective Views User’s Guide : Chapter 9 Properties : Getting and Setting Property Values
Getting and Setting Property Values
The property container interfaces IPropertyContainer and IODPropertyContainer both provide methods for getting and setting property values. The IPropertyContainer interface provides the GetPropertyValue() and PutPropertyValue() methods to get and set the property values as variants. Since dealing with VARIANTs can be cumbersome, the IODPropertyContainer interface provides a group of GetValue() and SetValue() methods, which are overloaded for several common data types. Either interface is equally valid for accessing property values.
Example 10 uses the IODPropertyContainer interface to disable rotation for a symbol component. Notice that the rotation property is nested in the edit property object and is accessed by combining the base property ID for the edit properties with the property ID for the rotation property.
Example 10 – Setting property values
void CMyController::OnInsertMySymbol()
{
CODSymbolComponent* pSymbol = new CODSymbolComponent();
pSymbol ->Create(IDR_MYSYMBOL);
OnInsertSymbol(pSymbol);
pSymbol->SetValue(OD_PROP_EDIT + OD_EDIT_CANROTATE, FALSE);
}
The code segment in Example 11, taken from the CODController class, retrieves the values of two properties using the GetValue() method.
Example 11 – Getting property values
void CODController::DblHit(UINT nFlags, CPoint ptDev, int nButton)
{
CPoint ptLog = ptDev;
VpDPtoLP(&ptLog);
CODComponent* pCompHit = GetVp()->ComponentHitTest(ptLog);
if (pCompHit != NULL)
{
int nHorzAlignment;
if (pCompHit->GetValue(OD_PROP_HORZ_ALIGNMENT, nHorzAlignment))
{
// Component has the horizontal alignment property. Value is
// is in the nHorzAlignment variable.
}
else
{
// Component doesn’t support the horizontal
// alignment property.
}
BOOL bCanScale;
if (pCompHit->GetValue(OD_PROP_EDIT + OD_EDIT_CANSCALE,
bCanScale))
{
// bScale contains a boolean value that indicates if
// the component can be scaled.
}
else
{
// Component doesn’t have any edit properties.
}
}
}