Compartir a través de


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

Nota:

Los grupos de interés de la comunidad ahora se han movido de Yammer a Microsoft Viva Engage. Para unirse a una comunidad viva Engage y participar en las últimas discusiones, rellene el formulario Solicitar acceso a Finance and Operations Viva Engage Community y elija la comunidad a la que desea unirse.

En este artículo se describen las funciones en tiempo de ejecución de reflexión.

classIdGet

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

int classIdGet(class object)

Parámetros

Parámetro Description
objeto Objeto para el que se va a obtener el identificador de clase.

Valor devuelto

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 de índice para los que se ha asignado espacio en una matriz X++.

int dimOf(anytype object)

Parámetros

Parámetro Description
objeto Matriz de la que se va a determinar el tamaño de dimensión.

Valor devuelto

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

Observaciones

La función dimOf está pensada para matrices X++ declaradas 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 X++. Estos son los tipos de matriz que la función dimOf no acepta:

  • str
  • contenedor
  • 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 especificado por un número de identificador de tabla y un número de identificador de campo.

str fieldId2Name(int tableid, int fieldid)

Parámetros

Parámetro Description
tableid Número de identificador de la tabla. Nota: Use la función tableName2Id para especificar el identificador de una tabla.
fieldid Número de identificador del campo.

Valor devuelto

Nombre del campo.

Observaciones

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 especificado por un número de identificador de tabla y un número de identificador de campo.

str fieldId2PName(int tableid, int fieldid)

Parámetros

Parámetro Description
tableid Número de identificador de la tabla. Nota: Use la función tableName2Id para especificar el identificador de una tabla.
fieldid Número de identificador del campo. Nota: Use la función fieldName2Id para especificar el identificador de un campo.

Valor devuelto

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 identificador de campo del campo de tabla especificado por un número de identificador de tabla y un número de identificador de campo.

int fieldName2Id(int tableid, str fieldname)

Parámetros

Parámetro Description
tableid Número de identificador de la tabla. Nota: Use la función tableName2Id para especificar el identificador de una tabla.
fieldname Nombre del campo.

Valor devuelto

Identificador del campo especificado por 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)

Parámetros

Parámetro Description
tableid Identificador de la tabla a la que pertenece el índice.
indexid Identificador del índice.

Valor devuelto

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)

Parámetros

Parámetro Description
tableid Identificador de la tabla a la que pertenece el índice.
indexname El nombre del índice.

Valor devuelto

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)

Parámetros

Parámetro Description
_tableid Identificador de la tabla.

Valor devuelto

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)

Parámetros

Parámetro Description
_fieldid Identificador de la tabla.

Valor devuelto

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)

Parámetros

Parámetro Description
_nombre Nombre de la tabla.

Valor devuelto

Identificador 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)

Parámetros

Parámetro Description
_objeto Elemento para el que se va a devolver el tipo.

Valor devuelto

Valor de enumeración del sistema Types.

Example

En el ejemplo siguiente se comprueba 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.
}