Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.
These two base classes with the incredibly confusing names are really just empty shells. The difference between them is that Container’s shell is transparent, while Control’s is opaque. (We’ll handle the name conflict by referring to these classes with capital “C” and to the similarly named concepts with small “c”.)
Both of these classes are containers (note the small “c” here) that let you combine other controls (small “c” here, too) into a unified whole. Container gives you access to the individual objects inside, while Control hides those objects from others. Essentially, Control protects the objects inside from meddlers. In either case, though, you can access the PEMs of the resulting object.
You’ll use these classes as the foundation for building things you wish were in the product in the first place. For example, the date spinner class DateSpin in the CoolStuf library in the downloads (www.hentzenwerke.com) is really a sub-class of Container. Now that we’ve done the work for you, though, you can just drop a date spinner onto any form and use it as if it were a native control.
There’s a third similar base class, Custom, which lets you construct non-visual objects. Like Container, it gives you access to the things inside.
Container and Control have few PEMs of their own because there’s not much there until you put it there. With these base classes, you’re definitely likely to add custom properties and methods when you sub-class.
Property |
Value |
Purpose |
ControlCount |
Numeric |
The number of controls inside. |
Controls |
Collection |
References to the controls inside. |
Picture |
Character |
Name of a bitmap file that is tiled to produce "wallpaper" for the control. |
Method |
Purpose |
AddObject, RemoveObject |
Container only. These methods let you add and remove objects from the container at runtime. Control doesn't support them because you can't do this, since the controls are not exposed. |
The different behavior of Container and Control carries through to subclassing as well. When you subclass something based on Container, you can change the things inside the original Container. When you subclass an object based on Control, the objects inside don’t even show up in the property sheet. The class is truly a black box.
* See the DateSpin example in the downloads.
* Here's the beginning of the definition
* (as output by the Class Browser
* and prettied up just a little).
DEFINE CLASS datespin AS container
Width = 176
Height = 31
BackStyle = 0
BorderWidth = 1
*-- Currently chosen month
nMonth = 1
*-- Currently Chosen Day
nDay = 1
*-- Currently Chosen Year
nYear = 1900
Name = "datespin"
*-- Contain the date currently displayed
Value = .F.
ADD OBJECT label1 AS label WITH ;
Comment = "/", ;
FontBold = .F., ;
FontSize = 24, ;
BackStyle = 0, ;
Caption = "/", ;
Height = 18, ;
Left = 48, ;
Top = 5, ;
Width = 13, ;
Name = "Label1"
AddObject, ControlCount, Controls, Custom, Picture, RemoveObject