Partager via


ASELOBJ( ) Function

Places an object reference for the currently selected control or container that exists in the Form Designer, Class Designer, or code editing window into a specified variable array. When calling ASELOBJ( ) in a code editing window, the array also includes elements for forms (.scx), visual class libraries (.vcx), and #INCLUDE file names. You can also use ASELOBJ( ) to create control builders.

ASELOBJ( ArrayName, [ 1 | 2 | 3 ] )

Parameters

  • ArrayName
    Specifies the name of the array you want to use.

  • 1
    Creates a one-element array containing an object reference to the container for the currently active and selected control.

    For example, if the currently active and selected control is a spinner on a form, the array contains an element with the value "FORM." When calling ASELOBJ( ) in the Command window, include this argument.

    Note   When a page frame is selected, ASELOBJ( ) returns the name of the current page.

  • 2
    Creates a one-element array containing an object reference to the DataEnvironment object for the form. The DataEnvironment object makes it possible for you to determine the data environment properties of the form.

  • 3
    Creates three-element array containing information in context with the currently active code editing window: object reference to a container object, the full path and name of the .scx or .vcx file, and the full path and name of the #INCLUDE file, if available.

    If no code editing window is active, the ASELOBJ( ) uses information from the most recently activated class or Form designer. This is similar to behavior of ASELOBJ(,1) except the array contains the additional elements. This includes when ASELOBJ(,3) is used in the Command window because no code editing window is active when the Command window is active.

    The following table shows the order in which these elements appear.

    Array element Description
    1 Object reference to container object
    2 Full path and name of .scx or .vcx file
    3 Full path and name of #INCLUDE file, if available
    Note   If no #INCLUDE file is available, the third element contains an empty string.

Return Values

Numeric data type. ASELOBJ( ) returns 1 if successful or 0 if unsuccessful.

Remarks

If no controls are selected, and the argument, 1, is omitted, ASELOBJ( ) returns 0 and does not create the array. If no controls exist on the form, ASELOBJ( ) does not recognize the form as the selected control. If no controls are currently selected and the argument, 1, is included, ASELOBJ( ) returns 1.

If the array does not exist, Visual FoxPro automatically creates the array.

If the array exists but is not large enough to contain all the information, Visual FoxPro automatically increases the size of the array to accommodate the information. If the array is larger than needed, Visual FoxPro truncates the array.

If the array exists, and ASELOBJ( ) returns 0 because no controls are selected, the array remains unchanged. If the array does not exist, and ASELOBJ( ) returns 0, the array is not created.

Example

Before running the following example, open a new form in the Form Designer and add one or more controls with Caption properties, such as a Label or CommandButton, to the form. Select a number of these controls and then run the example. ASELOBJ( ) displays the names of the selected controls, and then changes the captions of the selected controls.

gnobjects = ASELOBJ(gaSelected)     && Create array of control names
IF gnobjects > 0  && 0 indicates no controls selected
   CLEAR
   DISPLAY MEMORY LIKE gaSelected     && Displays selected controls
   FOR nCnt = 1 TO gnobjects 
      ? gaSelected(nCnt).Caption + ' => New Caption ' ;
         + LTRIM(STR(nCnt))  && Display old and new caption
      gaSelected(nCnt).Caption = 'New Caption ' ;
         + ALLTRIM(STR(nCnt))  && Assign new caption
   NEXT
ENDIF

See Also

CREATE FORM | DataEnvironment Object | Form Designer | _ObjectReference( ) API Library Routine | AMOUSEOBJ( ) Function