3.4 Creating your own set of base classes

Creating your own set of base classes

Using Visual FoxPro base classes directly without subclassing is a big no-no. You should subclass each base class before instantiating it or using it in the Form Designer. This adds a lot of flexibility to the design. You can always go back later, change a couple of properties, modify some behavior or add new methods. This is especially important when starting with Visual FoxPro, because it makes a project more forgiving you can always go back and correct mistakes you made earlier in the cycle.

Creating your own set of classes makes it possible to make system-wide changes within a matter of minutes. Let's assume you discovered a bug that influences your whole system. I just had such a bug. I used the InteractiveChange and the ProgrammaticChange events to discover record pointer movement and other changes in text fields. However, sometimes this event wouldn't fire, so I added an assign method for the Value property in my textbox base class that fired an OnChange() method. I basically created my own system-wide event that would fire whenever the Value property changed. This helped to resolve a problem that had us hooked for months. After making this change (which took me only a couple of minutes), I was able to remove about 50 items from our bug-tracking system. I could do this only because I had created my own "top-level" entry point.

Using your own base classes does more than help to resolve your own mistakes and problems. You can also use them to change standard behavior or appearance. Maybe you don't like FoxPro's default font. No problem! Go to your base class and change it. It only takes a couple of minutes

This first level of subclasses is usually referred to as your own set of base or foundation classes. Once you have this class library in place, you can basically forget about FoxPro's original base classes. Unfortunately, there is no way to tell FoxPro to display these classes instead of the internal base classes. This leaves us with the risk of using the wrong set of classes, which might result in hard-to-find bugs.

Fortunately, there are a couple of tools that check class libraries and force the use of certain base classes. The PowerBrowser is one of these tools. It comes with some wizards that deal with all kinds of base class issues. This tool is freeware and can be downloaded from the Developer's Download Files at www.hentzenwerke.com. Future updates to this tool will be available at www.eps-software.com.

Some suggestions

When creating your set of base classes, you can take care of some issues you might run into in a later stage of your development cycle.

I'm always concerned with creating applications that provide an interface the user is familiar with. Usually I stick to the Microsoft Office standards. One of the first steps to meet these standards is to change the standard font for all controls from Arial to MS Sans Serif or to the newer Tahoma. Font size should be 8 points. However, this could lead to problems if the user runs large fonts. In this case I switch back to the Arial font, the logic for which is built into my base classes.

I also try to make sure all objects have a consistent programming interface. Unfortunately, many of the FoxPro base classes do things a little differently. Some have a Release method, some don't. Some containers support an Objects collection while others have specialized ones like Forms or Pages. Some objects have Show and Hide methods while others only have a Visible property. I can take care of all these issues right in my base classes and save myself a lot of headache later down the road.

I think you get the idea about what kind of things belong in your set of base classes. Keep in mind that all the changes you made are subclassed into every single class you use in your project. Therefore, you should be concerned about performance. Adding 10 milliseconds to the instantiation time of a textbox might end up adding another second or two when instantiating a complex form.

Having a powerful set of base classes can add a lot to your application and make it flexible for changes later on. Nevertheless, you should be very careful with the changes you make. A little change in a base class not only can fix a system-wide bug, but it also can introduce one. Keep in mind that one small change can affect your whole application.



Advanced Object Oriented Programming with Visual FoxPro 6. 0
Advanced Object Oriented Programming with Visual FoxPro 6.0
ISBN: 0965509389
EAN: 2147483647
Year: 1998
Pages: 113
Authors: Markus Egger

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net