Logo

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.

CREATE CLASSLIB, ADD CLASS, REMOVE CLASS, RENAME CLASS

These commands let you maintain class libraries (VCX) in code.

Usage

CREATE CLASSLIB LibFileName

This command creates a new, empty class library. By default, it has an extension of VCX. You can specify a different extension, but we don’t recommend it—the memo portion gets an FPT extension and the whole thing is pretty confusing. Go with the flow and use VCX/VCT.

Actually, in VFP 6, you can't specify a different extension. No matter what file name you give to CREATE CLASSLIB, the file is created with a VCX extension and the corresponding memo file gets a VCT extension. Even if you surround the file name with quotes, the VCX extension is added at the end. This bug was fixed in one of the service packs for VFP 6.

You can’t abbreviate the “classlib” portion of CREATE CLASSLIB to the first four letters because it conflicts with CREATE CLASS. You need at least CREA CLASSL.

SET SAFETY determines whether you get a dialog confirming you want to overwrite the class library if the library already exists.

Example

CREATE CLASSLIB MyStuf

Usage

ADD CLASS ClassName [ OF CurrentLibrary ] TO NewLibrary
    [ OVERWRITE ]
REMOVE CLASS ClassName OF LibFileName

These two commands add and remove existing classes. ADD CLASS lets you copy a class from one library to another. REMOVE CLASS, not surprisingly, deletes a class from a library. Be careful about removing classes—if other classes are based on the one you remove, they’re orphaned and unusable. (You may not see this effect right away. Until the class library is packed, the deleted class can be found.)

You need the OF clause in ADD CLASS only when the library containing the class you want to copy isn’t among the current set of libraries (set with SET CLASSLIB).

Think twice before you copy a class from one library to another. Normally, you don’t want to keep multiple copies of a class around because that defeats the whole purpose of OOP—reducing your maintenance burden. Think of ADD CLASS as something you do when you want to send only some of the classes in a library to someone else or when you want to move a class from one library to another, but not as something you do regularly. Ordinarily, you’ll subclass rather than copy.

Example

ADD CLASS DateSpin OF CoolStuf TO MyStuf
REMOVE CLASS DateSpin OF CoolStuf

Usage

RENAME CLASS OldClassName OF ClassLib TO NewClassName

As its name suggests, this command lets you change the name of a class in a class library. As with REMOVE CLASS, use this command with caution because it can result in orphaned classes. Subclasses based on the class do not get updated with the new name. Use the Class Browser’s Rename button instead to rename a class and any subclasses contained in the same library or any other library open in the Browser. The Browser’s Redefine button lets you clean up afterward if you mess up and rename a class that has offspring.

Example

RENAME CLASS DateSpin OF MyStuf TO DateSpinner

See Also

Create Class, Define Class, Modify Class, Set Classlib