Client tier code for some business objects can use the symbol code to verify the validity of values given for properties on placement and during edit through the property pages. For example, a stair can only support angle values within a certain range. Also, a ladder symbol which only supports a vertical ladder might need to have the angle field read-only only in the client tier.
The 3D API framework provides an interface ICustomPropertyManagement which should be realized by the symbol to support validation and management of the properties on the part.
Implementation of custom property management involves the following steps:
-
Realize ICustomPropertyManagement on the symbol.
-
OnPreLoad is called immediately before the properties are loaded in the property page control. Any change to the display status of properties can be done here.
Following code example demonstrates how to set the display status of a property to read-only:
OnPreLoad(ByVal oBusinessObject As BusinessObject, ByVal CollAllDisplayedValues As ReadOnlyCollection(Of PropertyDescriptor))
…
'Validate each property value.
For i As Integer = 0 To CollAllDisplayedValues.Count - 1
Dim oPropDescr As PropertyDescriptor = CollAllDisplayedValues(i)
Dim oPropValue As PropertyValue = oPropDescr.[Property]
Dim sPropName As String = oPropValue.PropertyInfo.Name
'Make all these properties read-only.
Select Case sPropName
Case "MyReadOnlyPropertyName"
oPropDescr.[ReadOnly] = True
Exit Select
End Select
…
Next
…
-
OnPropertyChange is called each time a property is modified. Any custom validation can be done here.
Following code example shows how to validate the value of a property on change in the property value.
OnPropertyChange(ByVal oBusinessObject As BusinessObject, ByVal CollAllDisplayedValues As ReadOnlyCollection(Of PropertyDescriptor), ByVal oPropToChange As PropertyDescriptor, ByVal oNewPropValue As PropertyValue, ByRef sErrorMessage As String) As Boolean
…
sInterfaceName = oPropToChange.[Property].PropertyInfo.InterfaceInfo.Name
sPropertyName = oPropToChange.[Property].PropertyInfo.Name
…
'Check the property value.
If sErrorMessage.Length > 0 Then
bOnPreLoad = False
Exit For
End If
…