共用方式為


X++ 反映執行階段函式

備註

社區興趣小組現在已從 Yammer 轉移到 Microsoft Viva Engage。 若要加入 Viva Engage 社群並參與最新的討論,請填寫 [ 要求存取財務和營運 Viva Engage 社群 表單 」 ,並選擇您要加入的社群。

本文說明反射執行階段函式。

classIdGet

擷取初始化物件所屬類別的數值識別碼 (類別識別碼)。

int classIdGet(class object)

參數

參數 Description
物件 要取得類別識別碼的物件。

返回值

指定物件的類別識別碼。

Example

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

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

dimOf

擷取 X++ 陣列中已配置空間的索引元素數目。

int dimOf(anytype object)

參數

參數 Description
物件 要確定維度大小的陣列。

返回值

如果 物件 參數的值是數組,則數組中的元素數;否則為 0 (零)。

備註

dimOf 函式適用於宣告為下列 X++ 基本類型的 X++ 陣列:

  • 布爾值
  • date
  • int
  • int64
  • real
  • UTC日期時間

一個例子是 int iAmounts[6];。 如果列舉值和擴充資料類型的陣列最終是以上述其中一個基本資料類型 (為基礎) ,也支援它們。 dimOf 函式不接受所有 X++ 基本類型的陣列。 以下是 dimOf 函數不接受的陣列類型:

  • str
  • 容器
  • 任何類型
  • 類別物件的陣列
  • 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.
***********/

fieldId2名稱

擷取字串,代表表格 ID 號碼及欄位 ID 號碼所指定之欄位名稱。

str fieldId2Name(int tableid, int fieldid)

參數

參數 Description
表格ID 資料表的 ID 號碼。 便條: 使用 tableName2Id 函數來指定資料表的 ID。
欄位識別碼 欄位的 ID 號碼。

返回值

欄位的名稱。

備註

若要傳回欄位名稱的可列印版本,請使用 fieldId2PName 函式。

Example

下列範例會將 fn 設定為 Customer (CustGroup) 資料表中欄位 ID 為 7 的欄位名稱。

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

fieldId2PName

擷取表格 ID 號碼和欄位 ID 號碼所指定的欄位的可列印名稱。

str fieldId2PName(int tableid, int fieldid)

參數

參數 Description
表格ID 資料表的 ID 號碼。 便條: 使用 tableName2Id 函數來指定資料表的 ID。
欄位識別碼 欄位的 ID 號碼。 便條: 使用 fieldName2Id 函數來指定欄位的 ID。

返回值

欄位的名稱。

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

欄位名稱2Id

擷取由表格 ID 號碼和欄位 ID 號碼指定的表格欄位的欄位 ID。

int fieldName2Id(int tableid, str fieldname)

參數

參數 Description
表格ID 資料表的 ID 號碼。 便條: 使用 tableName2Id 函數來指定資料表的 ID。
欄位名稱 欄位的名稱。

返回值

tableidfieldname 參數所指定的欄位 ID。

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

indexId2名稱

擷取索引的名稱。

str indexId2Name(int tableid, int indexid)

參數

參數 Description
表格ID 索引所屬資料表的識別碼。
indexid 索引的識別碼。

返回值

索引的名稱。

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

擷取索引的識別碼。

int indexName2Id(int tableid, str indexname)

參數

參數 Description
表格ID 索引所屬資料表的識別碼。
索引名稱 索引的名稱。

返回值

索引的識別碼。

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

tableId2名稱

擷取包含資料表名稱的字串。

str tableId2Name(int _tableid)

參數

參數 Description
_tableid 資料表的識別碼。

返回值

數據表的名稱。

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

擷取包含表格可列印名稱 (標籤) 的字串。

str tableId2PName(int _fieldid)

參數

參數 Description
_fieldid 資料表的識別碼。

返回值

表格的標籤。

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

擷取資料表的識別碼。

int tableName2Id(str _name)

參數

參數 Description
_名字 數據表的名稱。

返回值

資料表的識別碼。

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

type的

擷取元素的類型。

enum typeOf(anytype _object)

參數

參數 Description
_物體 要傳回類型之的元素。

返回值

類型系統列舉值。

Example

下列範例會測試容器中的第一個元素 c 是否是包含單一整數的另一個容器。

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