Procedure Rebuild_Constraints
Call: | Send Rebuild_Constraints |
The Rebuild_Constraints procedure builds the constraint set for a DDO. It reconstructs constraints for this DD object by sending Constrain to it.
RebuildAllConstraints can be sent to any DataDictionary object (DDO) within a DDO structure to rebuild all constraint within the structure.
Whenever a constraint is changed, Rebuild_Constraints must be sent to the DDO that was changed. In addition, Rebuild_Constraints should be sent to all DDOs that might be impacted by the change. This is required when constraints are inherited.
We therefore advise that you send Rebuild_Constraints to all DDOs within a DDO structure. RebuildAllConstraints does this. It sends Rebuild_Constraints to all DDOs in the structure. We advise that you send RebuildAllConstraints instead of sending Rebuild_Constraints. It is easier and less error prone. You still might use Rebuild_Constraints for augmentation but even this is unlikely.
If the property pbInheritConstraints is False, the Constrain message is not sent to all DDO servers (parents) of this object recursively, thus ensuring that clients respect the constraints of their servers.
The constrain message sends OnConstrain which is the event that you should use to define your constraints using the Constrain command.
The WebApp Framework automatically performs a Rebuild_Constaints for each request. So, if an OnConstrain method queries the session manager for the currently logged in user or relies on a Server (session) Web Property, then you don't need to send additional Rebuild_Constraints.
When a DDO structure first becomes in-use (i.e., when a view is activated) the message Rebuild_Constraints is sent to all DDOs in the structure. If you wish to change the constraint of a DDO you must send Rebuild_Constraints to that DDO for the change to take effect.
Property String psStateFilter '' : Object Customer_DD is a Customer_DataDictionary Procedure OnConstrain String sFilter Get psStateFilter to sFilter If (sFilter<>"") Begin Constrain Customer.State EQ sFilter End End_Procedure End_Object : : Procedure ChangeFilter String sNewState Set psStateFilter to sNewState Send Rebuild_Constraints of Customer_DD End_procedure
If a change is made in a a filter within a "constrain as" expression (e.g. Constrain Customer as (Customer.State=psStateFilter(self)), the constraint does not need to be rebuilt. Constrain as filters are evaluated each time a record is found and are therefore always up to date.
Rebuild_Constraints only rebuilds the constraints for the DDO that receives the message. If you wish to rebuild all constraints in all DDOs you may wish to broadcast the Rebuild_Constraints message to all DDOs.
Rebuild_Constraints will often result in constrain commands being executed. The constrain command may change the value of the Found indicator. If you are using the value of Found based on a previous operation, you should be aware that it may get changed.
Changing constraints dynamically can result in a state where a DDO can contain an invalid record, for example, if a record was loaded before and no records are found that meet the new constraint criteria. In this case, Rebuild_Constraints will not clear the DDO buffer. It is the developer's responsibility to check for this (test if the constraint is valid and clear the DDO buffer if not).