CreateObjectArray function
Syntax
CreateObjectArray(Class_Name, Array_of_Args)
Description
Use the CreateObjectArray function to return an instance of a class.
Use this function when you must pass in parameters to create the object and you don’t know when you write the code how many parameters are required. If you can create the object without passing in additional values, or if you know how many parameters are required, use the CreateObject function instead.
The array of parameters is an array of Any. It must be a one-dimensional array, that is, you cannot pass in an array of array of Any. You cannot pass in field references, that is, you cannot pass in references of the form:
RECORD.FIELDNAME
If you do not want to supply any parameters, you can use an empty array, or a reference to a Null array.
Parameters
| Parameter | Description |
|---|---|
|
Class_Name |
Specify the name of the class you want to create an instance of, as a string. |
|
Array_Of_Args |
Specify an Array of Any containing all parameters for creating an instance of the class. |
Returns
A reference to newly created object.
Example
The following is an example of the creation of an Application Class object where the number of parameters used to create the object varies, depending on data in the database.
local String &ClassName, &RecName;
local Record &Rec;
/* Read class name and parameter record name from the database. */
SQLExec("SELECT CLASSNAME, RECNAME FROM %TABLE(RECORD.CLASSDATA)", &ClassName, &RecName);
local Record &Rec = CreateRecord(@ ("RECORD." | &RecName));
/* Read the parameters from the database. */
local Array of Any &Params = CreateArrayAny();
SQLExec("%SelectAll(:1)", &Rec, &Params);
/* Create the object. */
local MyPackage:BaseClass &Obj = CreateObjectArray(&ClassName, &Params);