Partilhar via


AINSTANCE( ) Function

Places instances of a class into a variable array and returns the number of instances placed in the array.

AINSTANCE(ArrayName, cClassName)

Return Values

Numeric

Parameters

  • ArrayName
    Specifies the name of the array into which the instances are placed. If the array you specify doesn't exist, Visual FoxPro automatically creates the array. If the array exists and isn't large enough to contain all the instances, Visual FoxPro automatically increases the size of the array to accommodate the instances. If the array is larger than necessary, Visual FoxPro truncates the array. If the array exists and AINSTANCE( ) returns 0 because no instances are found, the array remains unchanged. If the array doesn't exist and AINSTANCE( ) returns 0, the array is not created.

    Only class instances assigned to variables and array elements with CREATEOBJECT( ) or NEWOBJECT( ) are placed into the array.

  • cClassName
    Specifies a Visual FoxPro base class name or a user-defined class name. The following table lists the Visual FoxPro base classes you can specify for cClassName:

    Base Class Names  
    ActiveDoc Label
    CheckBox Line
    Column ListBox
    ComboBox OLEControl
    CommandButton OLEBoundControl
    CommandGroup OptionButton
    Container OptionGroup
    Control Page
    Cursor PageFrame
    Custom ProjectHook
    DataEnvironment Relation
    EditBox Separator
    Form Session
    FormSet Shape
    Grid Spinner
    Header TextBox
    Hyperlink Timer
    Image ToolBar

Example

In the following example, CREATEOBJECT( ) is used to create two instances of the Visual FoxPro Form base class. AINSTANCE( ) is used to create an array named gaMyArray that contains the variable references (goINSTANCE1 and goINSTANCE2) for each form instance. The contents of the array are then displayed.

CLEAR ALL
goINSTANCE1 = CREATEOBJECT('Form')
goINSTANCE2 = CREATEOBJECT('Form')

CLEAR
? AINSTANCE(gaMyArray, 'Form')  && Returns 2, two form instances 
DISPLAY MEMORY LIKE gaMyArray  && Displays the references

See Also

ADD CLASS | AMEMBERS( ) | CREATE CLASS | CREATE CLASSLIB | CREATEOBJECT( ) | DEFINE CLASS