NEWOBJECT( ) Function

See Also

Creates a new class or object directly from a .vcx visual class library or program.

Syntax

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

Returns

Object

Arguments

cClassName

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

OLE objects are created with the following syntax for cClassName:

ApplicationName.Class

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

oExcelSheet = NEWOBJECT('Excel.Sheet')

cModule

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

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:

  1. Visual FoxPro base classes.

  2. User-defined class definitions in memory in the order they were loaded.

  3. Classes in the current program.

  4. Class libraries opened with SET CLASSLIB.

  5. Classes in procedure files opened with SET PROCEDURE.

  6. Classes in the Visual FoxPro program execution chain.

  7. The OLE registry if SET OLEOBJECT is ON.

cInApplication

Specifies the Visual FoxPro application (.exe, or .app) containing the .vcx visual class library you specify with cClassLibName. 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.

eParameter1, eParameter2, ...

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

Remarks

NEWOBJECT( ) allows you to create a new class or object without opening a .vcx visual class library or procedure file.

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