字典部件是一直可用的部件;不用定义它。基于字典部件的变量可能包括键及其相关值的集合,您可以在运行时添加和除去键和值条目。这些条目被视作记录中的字段。
row Dictionary { ID = 5, lastName = "Twain", firstName = "Mark", };
在声明中包括条目时,每个键名都是一定符合 EGL 命名约定的 EGL 标识。在运行时添加条目时,可以更加灵活一些;可以指定字符串文字、常量或变量,在这种情况下,常量可以是 EGL 保留字或者可以包括在标识中无效的字符。有关详细信息,请参阅动态访问的括号语法。
row.age = 30; row["Credit"] = 700; row["Initial rating"] = 500
row.lastname = "Clemens";
lastname String age, credit, firstCredit int; lastname = row.lastname; age = row.age; credit = row.credit; credit = row["Credit"]; firstCredit = row["Initial rating"];
Record myRecordPart x int; end
以下代码将类型为 myRecordPart 的变量放在字典中,然后更改原始变量中的值:
testValue int; myRecord myRecordPart; // sets a variable value and places // a copy of the variable into the dictionary. myRecord.x = 4; row Dictionary { theRecord myRecord; } // Places a new value in the original record. myRecord.x = 700; // Accesses the dictionary's copy of the record, // assigning 4 to testValue. testValue = row.theRecord.x;
row Dictionary { age = 30 }; newRow Dictionary { }; newRow = row // resolves to true if (newRow.age == 30) ; end
声明中的一组属性将影响处理字典的方式。一组特定于字典的函数向代码提供数据和服务。
row Dictionary { // properties caseSensitive = no, ordering = none, // fields ID = 5, lastName = "Twain", firstName = "Mark" age = 30; };
row Dictionary { // properties caseSensitive = no, ordering = none, // fields row.caseSensitive = "yes" row.ordering = 50, age = 30 };
age = row.age; age = row.AGE; age = row["aGe"];
age = row.age; age = row.AGE; age = row["aGe"];
属性 caseSensitive 的值会影响后面一节中描述的若干函数的行为。
选项如下所示:
如果属性 ordering 的值为“None”,则键的顺序(在调用函数 getKeys 时)可能与值的顺序(在调用函数 getValues 时)不同。
if (row.containsKey(age)) ; end
dictionaryName.containsKey(key String in) returns (Boolean)
根据输入字符串(key)在字典中是否为键,此函数解析为 true 或 false。如果字典属性 caseSensitive 被设置为 no,则不考虑大小写;否则函数将搜索完全匹配,包括大小写匹配。
containsKey 仅在逻辑表达式中使用。
dictionaryName.getKeys ( ) returns (String[ ])
此函数返回一组字符串,每个字符串都是字典中的键。
如果字典属性 caseSensitive 被设置为 no,则每个返回键为小写;否则每个返回键为存储键时所使用的大小写。
如果字典属性 ordering 被设置为 no,则不能依赖于返回键的顺序;否则顺序为该属性的描述中指定的顺序。
dictionaryName.insertAll(sourceDictionary Dictionary in)
此函数的行为方式就像一系列赋值语句将源字典(sourceDictionary)中的键与值条目复制至目标,目标也是一个字典,其名称限定函数名。
如果键在源中而不在目标中,则键与值条目将复制至目标。如果键既在源中又在目标中,则源条目的值将覆盖目标中该条目的值。在确定目标中的键是否与源中的键相匹配时,会受到每个字典中的属性 caseSensitive 的影响。