Примечание
Для доступа к этой странице требуется авторизация. Вы можете попробовать войти или изменить каталоги.
Для доступа к этой странице требуется авторизация. Вы можете попробовать изменить каталоги.
This article describes the reflection run-time functions.
Retrieves the numeric identifier (the class ID) of the class that the object that is initialized belongs to.
int classIdGet(class object)
Parameter | Description |
---|---|
object | The object to get the class ID for. |
The class ID of the specified object.
static void classIdGetExample(Args _args)
{
int i;
WorkTimeCheck w;
i = classIdGet(w);
print "Class ID for object is " + int2Str(i);
}
Retrieves the number of index elements that space has been allocated for in an X++ array.
int dimOf(anytype object)
Parameter | Description |
---|---|
object | The array to determine the dimension size of. |
If the value of the object parameter is an array, the number of elements in the array; otherwise, 0 (zero).
The dimOf function is intended for X++ arrays that are declared as the following X++ primitive types:
- boolean
- date
- int
- int64
- real
- utcDateTime
An example is int iAmounts[6];. Arrays of enumeration values and extended data types are also supported if they are ultimately based on one of the preceding primitive data types (such as int). The dimOf function doesn't accept arrays of all X++ primitive types. Here are the array types that the dimOf function doesn't accept:
- str
- container
- anytype
- Arrays of class objects
- Instances of the Array class
static void JobDimOfArrays(Args _args)
{
int iAmounts[20], iCounts[];
ABCModel enumAbcModel[22]; // Enum
ABCModelType exdtAbcModelType[24]; // Extended data type
anytype anyThings[26];
str sNames[28];
Array myArrayObj; // Class
info("Start of job.");
info("--(Next, normal int array, dimOf() accepts it.)");
info(int2Str(dimOf(iAmounts)));
info("--(Next, normal enum array, dimOf() accepts it.)");
info(int2Str(dimOf(enumAbcModel)));
info("--(Next, normal extended data type array (based on enum), dimOf() accepts it.)");
info(int2Str(dimOf(exdtAbcModelType)));
info("--(Next, dynamic int array, dimension not yet set.)");
info(int2Str(dimOf(iCounts)));
info("--(Next, dynamic int array, after dimension established.)");
iCounts[13] = 13;
info(int2Str(dimOf(iCounts)));
info(" == == == == == (Next, array types that dimOf() does not support.)");
info("--(Next, normal anytype array, dimOf() always returns 0.)");
info(int2Str(dimOf(anyThings)));
info("--(Next, an instance of class X++ Array, dimOf() always returns 0.)");
myArrayObj = new Array(Types::Integer);
myArrayObj.value(1,501);
info(int2Str(dimOf(myArrayObj)));
info("--(Next, the lastIndex method provides size information about Array instances.)");
info(int2Str(myArrayObj.lastIndex()));
info("--(Next, normal str array, dimOf() does not accept it, job is halted.)");
info(int2Str(dimOf(sNames)));
info("End of job.");
}
/************ Actual Infolog output
Message (11:10:06 am)
Start of job.
--(Next, normal int array, dimOf() accepts it.)
20
--(Next, normal enum array, dimOf() accepts it.)
22
--(Next, normal extended data type array (based on enum), dimOf() accepts it.)
24
--(Next, dynamic int array, dimension not yet set.)
0
--(Next, dynamic int array, after dimension established.)
16
== == == == == (Next, array types that dimOf() does not support.)
--(Next, normal anytype array, dimOf() always returns 0.)
0
--(Next, an instance of class X++ Array, dimOf() always returns 0.)
0
--(Next, the lastIndex method provides size information about Array instances.)
1
--(Next, normal str array, dimOf() does not accept it, job is halted.)
Error executing code: Illegal operation on this type of array. (C)JobsJobDimOfArrays - line 41
************/
/*********** Pop-up error dialog box
"Internal error number 25 in script."
This error is caused by the code line...
info(int2Str(dimOf(iCounts)));
...before iCounts was assigned at any index.
***********/
Retrieves a string that represents the name of the field that is specified by a table ID number and a field ID number.
str fieldId2Name(int tableid, int fieldid)
Parameter | Description |
---|---|
tableid | The ID number of the table. Note: Use the tableName2Id function to specify the ID of a table. |
fieldid | The ID number of the field. |
The name of the field.
To return a printable version of the field name, use the fieldId2PName function.
The following example sets fn to the name of the field in the Customer (CustGroup) table that has a field ID of 7.
static void fieldId2NameExample(Args _arg)
{
str fn;
fn = fieldId2Name(tableName2Id("Customer"),7);
}
Retrieves the printable name of the field that is specified by a table ID number and a field ID number.
str fieldId2PName(int tableid, int fieldid)
Parameter | Description |
---|---|
tableid | The ID number of the table. Note: Use the tableName2Id function to specify the ID of a table. |
fieldid | The ID number of the field. Note: Use the fieldName2Id function to specify the ID of a field. |
The name of the field.
static void fieldId2PNameExample(Args _arg)
{
str name;
tableid _tableId;
fieldid _fieldid;
_tableId = tableName2Id("Address");
_fieldId = fieldName2Id(_tableId, "Name");
name = fieldId2PName(_tableId, _fieldid);
print name;
}
Retrieves the field ID of the table field that is specified by a table ID number and a field ID number.
int fieldName2Id(int tableid, str fieldname)
Parameter | Description |
---|---|
tableid | The ID number of the table. Note: Use the tableName2Id function to specify the ID of a table. |
fieldname | The name of the field. |
The ID of the field that is specified by the tableid and fieldname parameters.
static void fieldName2IdExample(Args _arg)
{
int id;
id = fieldName2Id(tableName2Id("Address"), "Name");
// Returns 6. Name is the 6th field in the Address table.
print id;
}
Retrieves the name of an index.
str indexId2Name(int tableid, int indexid)
Parameter | Description |
---|---|
tableid | The ID of the table that the index belongs to. |
indexid | The ID of the index. |
The name of the index.
static void indexId2NameExample(Args _arg)
{
str s;
tableid id;
indexid idx;
id = tableName2Id("Address");
idx = indexName2Id(id, "AddrIdx");
s = indexId2Name(id, idx);
print "The result of calling indexId2Name is " + s;
}
Retrieves the ID of an index.
int indexName2Id(int tableid, str indexname)
Parameter | Description |
---|---|
tableid | The ID of the table that the index belongs to. |
indexname | The name of the index. |
The ID of the index.
static void indexName2IdExample(Args _arg)
{
indexid idx;
tableid id;
id = tableName2Id("Address");
idx = indexName2Id(id, "AddrIdx");
print "Index ID for index name AddrIdx of table Address is " + int2Str(idx);
}
Retrieves a string that contains the name of a table.
str tableId2Name(int _tableid)
Parameter | Description |
---|---|
_tableid | The ID of the table. |
The name of the table.
static void tableId2NameExample(Args _arg)
{
str s;
tableid id;
// Get the ID for table name Address.
id = tableName2Id("Address");
print "ID for table name Address is " + int2Str(id);
// Get the name from the table ID.
s = tableId2Name(id);
print "Name for table ID " + int2Str(id) + " is " + s;
// Get the printable name from the table ID.
s = tableId2PName(id);
print "Printable name for table ID " + int2Str(id) + " is " + s;
}
Retrieves a string that contains the printable name (the label) of a table.
str tableId2PName(int _fieldid)
Parameter | Description |
---|---|
_fieldid | The ID of the table. |
The label of the table.
static void tableId2NameExample(Args _arg)
{
str s;
tableid id;
// Get the ID for table name Address.
id = tableName2Id("Address");
print "ID for table name Address is " + int2Str(id);
// Get the name from the table ID.
s = tableId2Name(id);
print "Name for table ID " + int2Str(id) + " is " + s;
// Get the printable name from the table ID.
s = tableId2PName(id);
print "Printable name for table ID " + int2Str(id) + " is " + s;
}
Retrieves the ID of a table.
int tableName2Id(str _name)
Parameter | Description |
---|---|
_name | The name of the table. |
The ID of the table.
static void tableName2IdExample(Args _arg)
{
str s;
tableid id;
// Get the ID for the Address table name.
id = tableName2Id("Address");
print "ID for the Address table name is " + int2Str(id);
// Get the name from the table ID.
s = tableId2Name(id);
print "Name for table ID " + int2Str(id) + " is " + s;
// Get the printable name from the table ID.
s = tableId2PName(id);
print "Printable name for table ID " + int2Str(id) + " is " + s;
}
Retrieves the type of an element.
enum typeOf(anytype _object)
Parameter | Description |
---|---|
_object | The element to return the type for. |
A Types system enumeration value.
The following example tests whether the first element in a container, c, is another container that contains a single integer.
if(typeof(conpeek(c, 1)) != Types::Container ||
conlen(conpeek(c, 1)) != 1 ||
typeof(conpeek(conpeek(c, 1), 1)) != Types::Integer)
{
// More code.
}