I'm in the process of expanding my knowledge and use of Class Modules.
I've perused MSDN and this and other sites, and I'm pretty comfortable
with my understanding of Class Modules with the exception of custom
Collection Classes.
Background: I'm developing an A2K .mdb to be deployed as an .mde at my
current job-site. It has several custom controls which utilize custom
classes to wrap built-in controls, and add additional functionality. In
my job, I'm only at this site for about another year, and I'd like for
the folks that follow me here to be able to add the same custom
controls with minimal effort on forms they may need to construct down
the road. Making them a custom class also reduces the repetition of
reinventing them for every form I construct.
Details on the controls:
Type1 is an image control that acts like a command/toggle button. The
control has three states and is used to call code to bring up the
Office Assistant to serve a WhatsThis type function. That functionality
doesn't require a compiled help file, but gets its display inputs from
the database itself. This control has three states. Initially it is
flat with a dimmed image. OnMouseMove it is raised with a clear image.
OnClick it is armed for Assistant calls, and the image is sunken with a
dark image. On subsequent Clicks, the Assistant goes away, and the
button returns to its raised state. OnMouseOut which is simulated using
ctl.Section.OnM ouseMove, the button returns to its default, flat,
state.
Type2 is a label control that acts like a hyperlink. It has similar
OnMouseMove, OnMouseDown, and OnMouseUp functionality to Type1 and also
utilizes ctl.Section.OnM ouseMove to simulate MouseOut behaviour.
Both types are associated with existing controls using this code in the
form that utilizes them:
************
' Declarations section
************
Public/Private mclsControlX as CustomClass
' Public for Type1 to allow the Assistant to
' change the state of the control when
' cancelled and Private for Type2.
************
' Form_Load code
************
Set mclsControlX = New CustomClass
Set mclsControlX.Co ntrol(x, y) = ctlControlOnFor m
Problem 1: After reference to the aforementioned sources, I've been
able to create a custom Collection Class that wraps the built-in
Collection type. What I've been unable to do is assign all the
CustomClass objects to the same Collection. I've tried establishing a
reference to the collection in the CustomControl.C ontrol Property Set
procedure, but this has failed. I use this code for that Property Set:
************
' CustomClass module
************
Public Property Set Control(x ..., y ..., img as Image)
....
Dim col as CustomCollectio n
Set col = New CustomCollectio n
col.ClsControls .Add img, img.Name
The Initialize and Terminate events for the CustomCollectio n fire every
time this Property Set code runs and the Collection is neither singular
(collecting every control of TypeX), nor persistant. How do I make the
Collection both singular and persistant?
I tried using:
If col.ClsControls .Count > 0
But, that throws object Error 91 every time because this instance of
the CustomCollectio n hasn't been created, yet.
How do I set this CustomCollectio n up to wrap a built-in Collection and
become a container for all CustomClass objects of Type1 or Type2,
respectively?
Problem 2: I can't really tell when the Terminate event for the
CustomClass objects is firing. Since I don't want to leave unassociated
or dormant Class objects laying around in memory, I have been setting
the module level object variable that contains the reference to these
objects to Nothing in the Terminate event. Do I need to remove that
reference with the Nothing keyword to the Form_Unload event where the
controls are instantiated or is the Terminate event of the Class
sufficient?
Hope that's descriptive enough. If not, I'll try to clear the fog
wherever there is any.
Thanks in advance.
Jamey Shuemaker