Funzioni fase di esecuzione riflessione X++

Questo articolo descrive le funzioni di runtime di reflection.

classIdGet

Recupera l'identificatore numerico (ID classe) della classe a cui appartiene l'oggetto inizializzato.

int classIdGet(class object)

Parameters

Parameter Description
object Oggetto per cui ottenere l'ID classe.

Return value

ID classe dell'oggetto specificato.

Example

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

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

dimOf

Recupera il numero di elementi di indice allocati per in una matrice X++.

int dimOf(anytype object)

Parameters

Parameter Description
object Matrice di cui determinare le dimensioni.

Return value

Se il valore del parametro dell'oggetto è una matrice, il numero di elementi nella matrice; in caso contrario, 0 (zero).

Remarks

La funzione dimOf è destinata alle matrici X++ dichiarate come tipi primitivi X++seguenti:

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

Un esempio è int iAmounts[6];. Anche le matrici di valori di enumerazione e tipi di dati estesi sono supportate se sono basate su uno dei tipi di dati primitivi precedenti, ad esempio int. La funzione dimOf non accetta matrici di tutti i tipi primitivi X++. Ecco i tipi di matrice che la funzione dimOf non accetta:

  • str
  • container
  • anytype
  • Matrici di oggetti classe
  • Istanze della classe 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 stringa che rappresenta il nome del campo specificato utilizzando un numero ID tabella e un numero ID campo.

str fieldId2Name(int tableid, int fieldid)

Parameters

Parameter Description
tableid Numero ID della tabella. Nota: Utilizzare la funzione tableName2Id per specificare l'ID di una tabella.
fieldid Numero ID del campo.

Return value

Nome del campo.

Remarks

Per restituire una versione stampabile del nome del campo, utilizzare la funzione fieldId2PName .

Example

L'esempio seguente imposta fn sul nome del campo nella tabella Customer (CustGroup) con ID campo 7.

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

fieldId2PName

Recupera il nome stampabile del campo specificato utilizzando un numero ID tabella e un numero ID campo.

str fieldId2PName(int tableid, int fieldid)

Parameters

Parameter Description
tableid Numero ID della tabella. Nota: Utilizzare la funzione tableName2Id per specificare l'ID di una tabella.
fieldid Numero ID del campo. Nota: Usare la funzione fieldName2Id per specificare l'ID di un campo.

Return value

Nome 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 l'ID campo del campo tabella specificato utilizzando un numero ID tabella e un numero ID campo.

int fieldName2Id(int tableid, str fieldname)

Parameters

Parameter Description
tableid Numero ID della tabella. Nota: Utilizzare la funzione tableName2Id per specificare l'ID di una tabella.
fieldname Nome del campo.

Return value

ID del campo specificato dai parametri tableid e 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 il nome di un indice.

str indexId2Name(int tableid, int indexid)

Parameters

Parameter Description
tableid ID della tabella a cui appartiene l'indice.
indexid ID dell'indice.

Return value

Nome dell'indice.

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 l'ID di un indice.

int indexName2Id(int tableid, str indexname)

Parameters

Parameter Description
tableid ID della tabella a cui appartiene l'indice.
indexname Nome dell'indice.

Return value

ID dell'indice.

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 stringa contenente il nome di una tabella.

str tableId2Name(int _tableid)

Parameters

Parameter Description
_tableid L'ID della tabella.

Return value

Nome della tabella.

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 stringa contenente il nome stampabile (etichetta) di una tabella.

str tableId2PName(int _fieldid)

Parameters

Parameter Description
_fieldid L'ID della tabella.

Return value

Etichetta della tabella.

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 l'ID di una tabella.

int tableName2Id(str _name)

Parameters

Parameter Description
_name Nome della tabella.

Return value

L'ID della tabella.

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 il tipo di un elemento.

enum typeOf(anytype _object)

Parameters

Parameter Description
_object Elemento per cui restituire il tipo.

Return value

Valore di enumerazione di sistema Types .

Example

Nell'esempio seguente viene verificato se il primo elemento di un contenitore, c, è un altro contenitore che contiene un singolo numero intero.

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