This project is read-only.

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 Create[ControlName].
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
     With MyControl
          .AttachToEventHandler CreateEventHandler(CreateGenericReference(.Control.Parent, ccForm), False)
    End With

End Sub

The Create function accomplishes the following:
  1. 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.
  2. Creates a new instance of the composite control based on the control reference passed.
  3. 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.

Last edited Feb 16, 2011 at 3:41 AM by vba_junkie, version 2


No comments yet.