Funzioni fase di esecuzione riflessione X++

Note

I gruppi di interesse della community sono ora passati da Yammer a Microsoft Viva Engage. Per partecipare a una community Viva Engage e partecipare alle discussioni più recenti, compilare il modulo Request access to Finance and Operations Viva Engage Community e scegliere la community a cui si vuole partecipare.

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)

Parametri

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

Valore restituito

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)

Parametri

Parametro Description
object Matrice di cui determinare le dimensioni.

Valore restituito

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

Note

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

  • booleano
  • data
  • int
  • int64
  • autentico
  • 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
  • contenitore
  • 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)

Parametri

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

Valore restituito

Nome del campo.

Note

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)

Parametri

Parametro 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.

Valore restituito

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)

Parametri

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

Valore restituito

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)

Parametri

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

Valore restituito

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)

Parametri

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

Valore restituito

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)

Parametri

Parametro Description
_tableid L'ID della tabella.

Valore restituito

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)

Parametri

Parametro Description
_fieldid L'ID della tabella.

Valore restituito

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)

Parametri

Parametro Description
_nome Nome della tabella.

Valore restituito

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)

Parametri

Parametro Description
_oggetto Elemento per cui restituire il tipo.

Valore restituito

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