jwcolby
jwcolby at colbyconsulting.com
Tue Mar 3 13:41:01 CST 2009
A.D. If you are determined to move in this direction and you want to sink events, you would have to coerce the generic control object passed in to a specific control type using a case statement that determines the control type. I believe you could also use a variant to pass in the actual control (textbox, combo etc) and not have to do a coercion. I truly do not recommend this approach however. The number of control types is fixed, so a class for each type is usable. Additionally it turns out that you are really mostly interested in an even smaller subset of all of the controls, for example you probably not build a class for the line control, the rectangle, the page break, unbound object, picture etc. To this point I have mostly worked with bound controls, as well as the tab, page and command button. Thus I only have 9 control classes. I guess it really depends on how deep you get into the controls in your forms. Additionally I use what I call (for lack of a better name) clsGlobalInterface. It contains code that truly is common across the control classes. As an example it is almost critical to empty collections before setting the pointer to the collection to nothing. So I have a method of clsGlobalInterface that will iterate a collection and remove anything in it, calling the term event of whatever is in there just in case the object is a class. This is a mEmptyClass method that could reside in each and every control class (or as a function out in a module) but since the code is identical, I simply place the code in clsGlobalInterface. I then dim an instance of clsGlobalInterface in the header of each control class. I actually expose the clsGlobalInterface instance using a property sub in each control class, but mostly it is used by the class itself to get at such common code. It is also possible of course to place code out in a module of the library and call it from the control classes, however we are supposed to try really hard to make classes self contained where possible. Thus I prefer to place such code in clsGlobalInterface. Using this clsGlobalInterface I encapsulate truly global code while keeping my control class specific to each control. John W. Colby www.ColbyConsulting.com A.D.Tejpal wrote: > John, > > What I have in mind is a generic class, that morphs into a dedicated type as per the control passed to it. For example, if a text box is passed as argument, it acts as pure text box class. Similarly, for a combo box, it functions as pure combo box class. > > No doubt, the code content for such a class is more than that in tailor made class for single control. However, it offers the advantage of a common place to manage the code. Duplication of certain content across multitude of classes can be avoided. If any common improvement / enhancement in class code is found necessary, it can be done conveniently at one place. No need to edit all the scattered classes for individual controls. > > Best wishes, > A.D. Tejpal > ------------