Mike Lewis
Programmer
In thread184-1826292, Chris proposed an interesting idea, but it was one that required a certain method to be present in every object based on every VFP base class. The trouble is, as Chirs pointed out: "I can't write a parent class of which both a container and a textbox (and a listbox, editbox, grid, etc) can inherit." In other words, if you want to add the same property or method to controls based on different classes, you have to add each one individually, which is tedious and error-prone.
I'd like to suggest a partial solution.
Like most of us here, whenever I start a new project, I like to create a class library containing a "first generation" sub-class of each of the native classes. These sub-classes start out being the same as their respective parents, with the minimum of changes to their properties, events or methods. That way, if you later need to introduce some change to all the objects based of a given parent, these sub-classes will provide a way to do so.
Long ago, I wrote a simple program to create this first generation class library automatically. The following is a simplified version of that program:
Going one step further, it is possible to add one or more common properties to every one of those new classes. You just insert the required loObj.AddProperty() calls between the CREATEBOJECT() and the loObj.SaveAsClass().
Although this will add common properties, you cannot use it to add common methods, and so won't meet Chris's requirement. I can't off hand see a way round that. Nevertheless, I am posting this code in the hope that it might be useful in other situations.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips and downloads
I'd like to suggest a partial solution.
Like most of us here, whenever I start a new project, I like to create a class library containing a "first generation" sub-class of each of the native classes. These sub-classes start out being the same as their respective parents, with the minimum of changes to their properties, events or methods. That way, if you later need to introduce some change to all the objects based of a given parent, these sub-classes will provide a way to do so.
Long ago, I wrote a simple program to create this first generation class library automatically. The following is a simplified version of that program:
Code:
* Creates a first-level subclass of all (or most) of the
* VFP base classes.
lcRootLib = "RootClasses.vcx"
* Get alist of the names of the base classes
ALANGUAGE(aBase, 3)
FOR lnI = 1 TO ALEN(aBase)
lcBase = aBase(lnI)
lcName = "Root" + lcBase
* Create an object based on each of the base classes.
* We error-trap this to avoid problems caused by the
* few base classes that do not have the relevant methods
* (OLEBound, OLEContainer, Empty, and possibly others)
TRY
loObj = CREATEOBJECT(lcBase)
* Save it as a new class
loObj.SaveAsClass(lcRootLib, lcName)
CATCH
ENDTRY
ENDFOR
Going one step further, it is possible to add one or more common properties to every one of those new classes. You just insert the required loObj.AddProperty() calls between the CREATEBOJECT() and the loObj.SaveAsClass().
Although this will add common properties, you cannot use it to add common methods, and so won't meet Chris's requirement. I can't off hand see a way round that. Nevertheless, I am posting this code in the hope that it might be useful in other situations.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips and downloads