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.

SET CLASSLIB, Set(“ClassLib”), RELEASE CLASSLIB

SET CLASSLIB lets you ADD CLASS libraries to the list of places FoxPro looks for class definitions when you refer to one. RELEASE CLASSLIB removes a class library from that list. Set(“ClassLib”) shows you the current list.

Usage

SET CLASSLIB TO [ ClassLibrary1 [ IN AppOrExeFile1 ]
                [ ALIAS ClassAlias1 ]
                [, ClassLibrary2 [ IN AppOrExeFile2 ]
                [ ALIAS ClassAlias2 ] [ ... ] ]
                [ ADDITIVE ] ]

cClassList = SET( "CLASSLIB" )
RELEASE CLASSLIB ClassLibrary1 | ALIAS ClassAlias1
                 [ IN AppOrExeFile1 ]
                 [, ClassLibrary2 | ALIAS ClassAlias2
                 [ IN AppOrExeFile2 ] [ ... ] ]

Parameter

Value

Meaning

ClassLibraryx

Name

The file name of a class library to add to or remove from the search chain. For SET CLASSLIB, include the path if it's not in the FoxPro path.

Omitted

In SET CLASSLIB, remove all libraries from the search path.

AppOrExeFilex

Name

The name of an APP or EXE file into which the class library is built.

Omitted

Look for the class library as a separate file on disk, or in the current EXE or APP.

ClassAliasx

Name

An alias by which to refer to the class library.

Omitted

Use the file name (first part up to the ".") as the alias. If you use spaces in the file name (and please reconsider if you do!), they are replaced with underscores in the alias.

cClassList

Character

The complete list of class libraries that are currently being used, including paths and aliases.

Empty

No class libraries are in the search path.

Although Help doesn’t mention it, as the syntax diagram above shows, you can add multiple class libraries to the search path at once.

The alias gives you an alternate name for the library, which you can use in CREATEOBJECT() to distinguish among classes with the same name in different libraries.

Setting class libraries normally removes previous settings. Use ADDITIVE to add to the current list. SET CLASSLIB TO without a list is like issuing RELEASE CLASSLIB for the whole list.

The IN clause, added in VFP 5, lets you add libraries that exist only as part of an application to the search path. It also protects you when the same name is used for a class library found in an application and on the disk.

Class libraries are searched in the order they’re added to the search list. Adding a library to the list that’s already there doesn’t change the search order.

The Help for SET CLASSLIB says that classes loaded in memory are searched pretty early in the search chain. We haven’t been able to find a way to get a class to hang around in memory once the source for it (whether a program, class library or procedure file) is removed.

However, once you’ve instantiated a class, you can release the class library. The class can still find its code. We’re not sure whether the instance carries a copy of its code with it at all times or goes back to the class library to find it. Our instinctive feeling is the former, but a class library cannot be deleted while an object inheriting from it is instantiated, so objects do maintain some hold on their classes. And clearly, VFP has some mechanism to look in class libraries for code, because it can find its way up the inheritance tree without our help.

RELEASE CLASSLIB was enhanced in a couple of ways in VFP 5, but they didn't do a very good job of it. The IN clause was added to allow you to release class libraries that are built into applications. However, using it gives an error unless there's a class library of the same name in the directory from which you SET the CLASSLIB. You have to use the ALIAS form of the command to release such a class library.

But wait, there's more. You can use the IN clause only once in RELEASE CLASSLIB, and it must be the last clause. Any libraries you list after the IN clause are ignored. Although it's documented that way, we consider this a bug because there's no logical reason for the command to behave this way.

Example

SET CLASSLIB TO CoolStuf
CREATE CLASS MyDateSpinner OF MyStuff AS DateSpinner
RELEASE CLASSLIB CoolStuf

cOldClassLib = SET("CLASSLIB")
SET CLASSLIB TO Connect ADDITIVE
oConn = CreateObject("ConnMgr")
SET CLASSLIB TO &cOldClassLib

See Also

Create ClassLib, CreateObject(), NewObject(), Release, Release Library, Release Procedure, Set Library, Set Path, Set Procedure