ElementIndex(Key: Integer): Integer;
Key. Element key.
The property is read-only.
The ElementIndex property returns element index by key.
If there is not an element with a specified key in a dictionary, ElementIndex returns value -1.
If parameter Key = -2, ElementIndex returns index of a dictionary root element.
Executing the example requires an MDM repository with the RDS identifier that contains the dictionary with the DICTIONARY identifier. It is also necessary to add links to the Metabase, Rds system assemblies.
Sub UserProc;
Var
Mb: IMetabase;
RdsKey: Integer;
Dict: IRdsDictionaryInstance;
Elements: IRdsDictionaryElements;
Children: IRdsDictionaryElementArray;
i: Integer;
Index: Integer;
Key: Integer;
Element: IRdsDictionaryElement;
Begin
Mb := MetabaseClass.Active;
RdsKey := Mb.ItemById("OBJ601").Key;
Dict := Mb.ItemByIdNamespace("OBJ607", RdsKey).Open(Null) As IRdsDictionaryInstance;
Elements := Dict.Elements;
Children := Elements.Children(-2);
For i := 0 To Children.Count - 1 Do
Key := Children.Item(i);
Index := Elements.ElementIndex(Key);
Element := Elements.Item(Index);
Debug.WriteLine(Element - ' + Element.Name + ' Index - + Element.ElementIndex.ToString);
End For;
End Sub UserProc;
After executing the example names and indexes of child elements for a dictionary root element are displayed in the console window.
See also: