DGEN()

AInstance()

This function lets you find all the instances of any class. It puts the list into an array. Because you can instantiate a class as many times as you want, it seems like it would be convenient to be able to find all the instances. However, we have yet to actually use this function other than to test it.

Usage

nInstanceCount = AINSTANCE( ArrayName, cClassName )

Parameter

Value

Meaning

ArrayName

Array Name

The array to hold the instance references.

cClassName

Character

The name of the class for which to find instances. Both VFP base classes and user-defined classes can be specified.

nInstanceCount

Positive Number

The number of items in the array, which equals the number of references to cClassName found.

0

No instances of cClassName were found.


Unlike the similar ASELOBJ() function, each element of the array holds the name of an object, not an object reference to the object. Using indirect variable references or macro substitution, you can operate on the objects themselves.

Although you can do something like the previous example, there's a much easier way to deal with a collection of objects. Simply use an array to hold the object references in the first place. Visual FoxPro allows you to do something like this:

DIMENSION aForms[3]   FOR nCnt = 1 TO 3    aForm[nCnt] = CREATEOBJECT('form') ENDFOR
Watch out for one thing with AINSTANCE(). If several variables refer to the same object, you still get one array item for each variable. So, if you're using the references to change all objects of the class, you may hit some of them more than once. On the other hand, this feature makes AINSTANCE() ideal for ensuring that you actually release an object when you want to.

Note that AINSTANCE() shares the same first four letters as AINSERT(); therefore you must use at least five letters for AINSTANCE().

AINSTANCE() may be helpful when you're dealing with cases where you haven't created the objects yourself, but you need to find out what's out there—for example, in a Builder or a handler of some sort.

Note that AINSTANCE() can't be used to find out about OLE classes such as Project and File. However, the application object offers collections that let you check on those as needed.

See Also

AClass(), AMembers(), Application, Array Manipulation, ASelObj(), CreateObject()


View Updates

Copyright © 2002 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. All Rights Reserved.



Hacker's Guide to Visual FoxPro 7. 0
Hackers Guide to Visual FoxPro 7.0
ISBN: 1930919220
EAN: 2147483647
Year: 2001
Pages: 899

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