Writing Support Modules for Composite Controls
Support modules for composite controls contain code that is used within a Composite Control class, but does not need to be included in the class. By offloading these procedures into Standard Modules, the memory usage for a given class may be significantly
reduced with little performance penalty. While the Support module for a Composite Control may contain a variety of functions, the most important is the control creation function, typically named
The typical Create function contains the following code:
Public Sub CreateMyCompositeControl(Control_Reference As Control_Reference_Type)
Dim MyControl As cControl_MyCompositeControl
'create the control
Set MyControl = CompositeControls.CustomControls.GetOrCreate(CreateGenericReference(Tab_Control, ccControl_Reference_Type), ccMyCompositeControl)
'Create the event handler for the parent form and attach the new control to it
.AttachToEventHandler CreateEventHandler(CreateGenericReference(.Control.Parent, ccForm), False)
The Create function accomplishes the following:
- Wraps non-Composite Control objects in a cControl_Generic object using the
CreateGenericReference() function. If the control reference passed implements the iControl interface, the
CreateGenericReference function call is not necessary.
- Creates a new instance of the composite control based on the control reference passed.
- Attaches the new control's Startup and
Terminate events to the parent control / form / report using the
AttachToEventHandler() function. Note that the parent of the control reference is assumed to be a Form by default.