The Viewer Logic class supports developers to separate viewer event handling logic from the actual layout of viewers. This includes the ability to handle input control based events in a single place, no matter if due to layout constraints the controls are spread over more than a single viewer (GroupAssignLink) or certain fields are not used on viewers at all (e.g. due to customization etc.) and thus might cause errors.
To facilitate this developers can move the viewer event handling logic from the actual SmartViewerControl derived classes into ViewerLogicClasses.
The name of a ViewerLogicClass needs to be registered on the viewer instance in the form using the ViewerLogicClass property and the viewer will load and initialize this class during the Load event.
The ViewerLogicClasses needs to implement the Interface:
...
Consultingwerk.SmartComponents.Base.SmartViewerLogic
When using the ViewerLogicClass to handle events of controls on a viewer you need to subscribe to events of the Controls and also unsubscribe those events when the Form containing the Viewer is closed to prevent memory leaks.
...
Code Block | ||
---|---|---|
| ||
/*------------------------------------------------------------------------------ Purpose: Subscribes the events for an attached viewer instance Notes: This method needs to be implemented by the Viewer Logic class and is supposed to subscribe to control events ------------------------------------------------------------------------------*/ METHOD OVERRIDE PUBLIC VOID SubscribeEvents (): END METHOD . /*------------------------------------------------------------------------------ Purpose: Unsubscribes the events for an attached viewer instance Notes: This method needs to be implemented by the Viewer Logic class and is supposed to unsubscribe from control events ------------------------------------------------------------------------------*/ METHOD OVERRIDE PUBLIC VOID UnsubscribeEvents (): END METHOD . |
The ViewerLogicClass base class provides three API’s to query the availability of Controls data bound to certain fields in the binding source on the linked viewers and to retrieve the references to those controls:
Code Block | ||
---|---|---|
| ||
/*------------------------------------------------------------------------------ Purpose: Returns the reference to the first Control that is bound to the named field of the binding source Notes: Searchs all Controls in the owning viewer and also GroupAssignLinked viewers @param pcBindingPropertyName The name of the field in the ProBindingSource @return The bound Control of ? when no Control is bound ------------------------------------------------------------------------------*/ METHOD PUBLIC System.Windows.Forms.Control GetBoundControl (pcBindingPropertyName AS CHARACTER). /*------------------------------------------------------------------------------ Purpose: Returns the list of references of the Controls that are bound to the named field of the binding source Notes: Returns all Controls in the owning viewer and also GroupAssignLinked viewers @param pcBindingPropertyName The name of the field in the ProBindingSource @return The List of bound Controls ------------------------------------------------------------------------------*/ METHOD PUBLIC "System.Collections.Generic.List<System.Windows.Forms.Control>" GetBoundControls (pcBindingPropertyName AS CHARACTER). /*------------------------------------------------------------------------------ Purpose: Returns logical value indicating if the Viewer contains a Control that is bound to the named field Notes: Includes Group Assigned viewers @param pcBindingPropertyName The name of the field in the ProBindingSource @return Logical value indicating if a bound control exists ------------------------------------------------------------------------------*/ METHOD PUBLIC LOGICAL HasBoundControl (pcBindingPropertyName AS CHARACTER). |
...
Code Block | ||
---|---|---|
| ||
{Consultingwerk/foreach.i System.Windows.Forms.Control oControl in "THIS-OBJECT:GetBoundControls(""CustNum"")"} oControl:Validating:Subscribe (ValidatingEventHandler). END. |
When you need to subscribe to events that are not defined only on the specific Control type (e.g. CheckChanged of the combo-box Controls), the Control reference received from the GetBoundControl/GetBoundControls API’s need to be casted.
The validating event handler needs to be implemented in the viewer logic class with an appropriate signature.
...