Funciones de tiempo de ejecución de reflexión de X++

Este artículo describe las funciones de ejecución en tiempo de reflexión.

classIdGet

Recupera el identificador numérico (el ID de clase) de la clase a la que pertenece el objeto inicializado.

int classIdGet(class object)

Parameters

Parameter Description
object El objeto para el que se va a obtener el identificador de clase.

Return value

El identificador de clase del objeto especificado.

Example

static void classIdGetExample(Args _args)
{
    int i;
    WorkTimeCheck w;

    i = classIdGet(w);
    print "Class ID for object is " + int2Str(i);
}

dimOf

Recupera el número de elementos índice para los que se asigna espacio en un array X++.

int dimOf(anytype object)

Parameters

Parameter Description
object La matriz de la que se va a determinar el tamaño de dimensión.

Return value

Si el valor del parámetro object es una matriz, el número de elementos de la matriz; de lo contrario, 0 (cero).

Remarks

La función dimOf está pensada para matrices de X++ que se declaran como los siguientes tipos primitivos de X++:

  • boolean
  • date
  • int
  • int64
  • real
  • utcDateTime

Un ejemplo es int iAmounts[6];. También se admiten matrices de valores de enumeración y tipos de datos extendidos si se basan en última instancia en uno de los tipos de datos primitivos anteriores (como int). La función dimOf no acepta matrices de todos los tipos primitivos de X++. Estos son los tipos de matriz que la función dimOf no acepta:

  • str
  • container
  • anytype
  • Matrices de objetos de clase
  • Instancias de la clase Array

Example

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.
***********/

fieldId2Name

Recupera una cadena que representa el nombre del campo que especificas usando un número de ID de tabla y un número de ID de campo.

str fieldId2Name(int tableid, int fieldid)

Parameters

Parameter Description
tableid El número de ID de la tabla. Nota: Use la función tableName2Id para especificar el identificador de una tabla.
fieldid El número de identificación del campo.

Return value

El nombre del campo.

Remarks

Para devolver una versión imprimible del nombre del campo, use la función fieldId2PName .

Example

En el ejemplo siguiente se establece fn en el nombre del campo de la tabla Customer (CustGroup) que tiene un identificador de campo de 7.

static void fieldId2NameExample(Args _arg)
{
    str fn;
    fn = fieldId2Name(tableName2Id("Customer"),7);
}

fieldId2PName

Recupera el nombre imprimible del campo que especifiques usando un número de ID de tabla y un número de ID de campo.

str fieldId2PName(int tableid, int fieldid)

Parameters

Parameter Description
tableid El número de ID de la tabla. Nota: Use la función tableName2Id para especificar el identificador de una tabla.
fieldid El número de identificación del campo. Nota: Utilice la función fieldName2Id para especificar el identificador de un campo.

Return value

El nombre del campo.

Example

static void fieldId2PNameExample(Args _arg)
{
    str name;
    tableid _tableId;
    fieldid _fieldid;

    _tableId = tableName2Id("Address");
    _fieldId = fieldName2Id(_tableId, "Name");
    name = fieldId2PName(_tableId, _fieldid);
    print name;
}

fieldName2Id

Recupera el ID de campo del campo de la tabla que especifiques usando un número de ID de tabla y un número de ID de campo.

int fieldName2Id(int tableid, str fieldname)

Parameters

Parameter Description
tableid El número de ID de la tabla. Nota: Use la función tableName2Id para especificar el identificador de una tabla.
fieldname El nombre del campo.

Return value

El ID del campo que especifican los parámetros tableid y fieldname .

Example

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;
}

indexId2Name

Recupera el nombre de un índice.

str indexId2Name(int tableid, int indexid)

Parameters

Parameter Description
tableid El identificador de la tabla a la que pertenece el índice.
indexid El identificador del índice.

Return value

El nombre del índice.

Example

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;
}

indexName2Id

Recupera el identificador de un índice.

int indexName2Id(int tableid, str indexname)

Parameters

Parameter Description
tableid El identificador de la tabla a la que pertenece el índice.
indexname El nombre del índice.

Return value

El identificador del índice.

Example

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);
}

tableId2Name

Recupera una cadena que contiene el nombre de una tabla.

str tableId2Name(int _tableid)

Parameters

Parameter Description
_tableid El id. de la tabla.

Return value

El nombre de la tabla.

Example

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;
}

tableId2PName

Recupera una cadena que contiene el nombre imprimible (la etiqueta) de una tabla.

str tableId2PName(int _fieldid)

Parameters

Parameter Description
_fieldid El id. de la tabla.

Return value

La etiqueta de la tabla.

Example

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;
}

tableName2Id

Recupera el identificador de una tabla.

int tableName2Id(str _name)

Parameters

Parameter Description
_name El nombre de la tabla.

Return value

El id. de la tabla.

Example

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;
}

typeOf

Recupera el tipo de un elemento.

enum typeOf(anytype _object)

Parameters

Parameter Description
_object Elemento para el que se va a devolver el tipo.

Return value

Un valor de enumeración del sistema Tipos .

Example

En el ejemplo siguiente se prueba si el primer elemento de un contenedor, c, es otro contenedor que contiene un único entero.

if(typeof(conpeek(c, 1)) != Types::Container ||
conlen(conpeek(c, 1)) != 1 ||
typeof(conpeek(conpeek(c, 1), 1)) != Types::Integer)
{
    // More code.
}