Partager via


NEWOBJECT( ) Function

Creates a new class or object directly from a visual class library (.vcx) file or program (.prg) file without opening the file.

NEWOBJECT(cClassName [, cModule [, cInApplication
   [, eParameter1, eParameter2, ...]]])

Parameters

  • cClassName
    Specifies the class or object from which the new class or object is created.

  • cModule
    Specifies a .vcx file or Visual FoxPro program (.prg, .mpr, .app, .exe, and so on) containing the class or object specified with cClassName. The default is a .vcx file. If you specify a program file, you must include an extension.

    Note   A class library can have an alias. To specify a class or object from a class library with an alias, include the class library alias followed by a period and the object name.

    If cModule is omitted, or is the empty string or the null value, Visual FoxPro searches for the class or object in the following order:

    • Visual FoxPro base classes
    • Classes in the current program
    • Class libraries opened with SET CLASSLIB
    • Classes in procedure files opened with SET PROCEDURE
    • Classes in the Visual FoxPro program execution chain
    • The OLE registry if SET OLEOBJECT is ON
  • cInApplication
    Specifies the Visual FoxPro application (.exe or .app) containing the .vcx file you specify with cModule. You must include an extension for the application. CInApplication is ignored if cModule is omitted, or if cInApplication is the empty string or the null value.

    If you want to use the cInApplication parameter, you must specify the name of .vcx file for cModule. You cannot pass the name of a .prg file or compiled program (.fxp).

  • eParameter1, eParameter2, ...
    Specifies optional parameters that are passed to the Init event procedure for the class or object.

Return Values

Object

Remarks

To assign the object reference returned by NEWOBJECT( ) to a variable or array element, use the equal sign (=) or STORE command. If an object assigned to a variable or array element is released, the variable or array element contains the null value. To remove the variable or array element from memory, use the RELEASE command.

For NEWOBJECT( ), Visual FoxPro performs an internal SET CLASSLIB or SET PROCEDURE for the second or third parameters using the ADDITIVE clause where the parameters are first used to determine the search order. If these parameters already exist in the SET CLASSLIB or SET PROCEDURE list, Visual FoxPro rearranges the order in the list so they come first. Visual FoxPro then locates all the classes, creates the object, and calls the Init events. Finally, Visual FoxPro restores the original SET CLASSLIB or SET PROCEDURE list if the installation did not change list.

OLE objects are created with the following syntax for cClassName:

ApplicationName.Class

For example, to create a Microsoft Excel worksheet, which supports Automation, use the following syntax:

oExcelSheet = NEWOBJECT('Excel.Sheet')

See Also

Class Designer | CREATE CLASS | CREATE CLASSLIB | CREATEOBJECT( ) | DEFINE CLASS | NewObject Method