CreateByObject(ObjectKey: Integer);
CreateByObject(ObjectKey: uinteger);
ObjectKey. Repository object key.
The CreateByObject constructor creates a new dependencies template in accordance with parameters of repository object.
To create a new dependencies template in accordance with the specified parameters of object, MDM dictionary and dictionary element, use the MbElementDependentTemplateClass.Create constructor.
Executing the example requires MDM dictionaries with the DICT and DICT1 identifiers.
Add links to the Metabase, Rds system assemblies.
Sub UserProc;
Var
MB: IMetabase;
Obj, Dictionary: IMetabaseObjectDescriptor;
RdsDictIns: IRdsDictionaryInstance;
Elements: IRdsDictionaryElements;
Depends: IMbElementDependents;
Template, Value: IMbElementDependentTemplate;
ObjKey, DictKey, ElemKey: Integer;
Begin
MB := MetabaseClass.Active;
Obj := MB.ItemById("DICT1");
Dictionary := MB.ItemById("DICT");
RdsDictIns := Dictionary.Open(Null) As IRdsDictionaryInstance;
Elements := RdsDictIns.Elements;
// Object settings:
Obj := Obj.EditDescriptor;
Obj.ElementDependenciesTrackingType := MbElementDependenciesTrackingType.Dependecies;
Obj.SaveDescriptor;
/// Settings:
DictKey := Dictionary.Key;
ObjKey := Obj.Key;
ElemKey := Elements.Element(1); // for the first dictionary element
// Template:
Template := New MbElementDependentTemplateClass.CreateByObject(ObjKey);
Template.ElementKey := Elements.Element(4);
// Collection of dependencies:
Depends := Mb.ElementDependentsDatabase.New_;
Depends.Where := Template;
Value := New MbElementDependentTemplateClass.Create(ObjKey, DictKey, ElemKey);
Depends.Add(Value);
Depends.Database.Update(Depends);
Debug.WriteLine("=== Object: " + Obj.Name + " ===");
Debug.WriteLine("Track links to elements from other objects: ");
If Obj.TrackElementDependencies = True Then
Debug.WriteLine(" - option is enabled");
Else
Debug.WriteLine(" - option is disabled");
End If;
Debug.WriteLine("=== Dictionary: " + Dictionary.Name + " ===");
Debug.WriteLine("Track links to elements from other objects: ");
If Dictionary.TrackElementDependents = True Then
Debug.WriteLine(" - option is enabled");
Else
Debug.WriteLine(" - option is disabled");
End If;
End Sub UserProc;
After executing this example the console window displays information about whether the Track Links to Elements from Other Objects option is enabled for each dictionary.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.Metabase;
Imports Prognoz.Platform.Interop.Rds;
Public Shared Sub Main(Params: StartParams);
Var
MB: IMetabase;
Obj, Dictionary: IMetabaseObjectDescriptor;
RdsDictIns: IRdsDictionaryInstance;
Elements: IRdsDictionaryElements;
Depends: IMbElementDependents;
DependTemplClassT, DependTemplClassV: MbElementDependentTemplateClassClass = New MbElementDependentTemplateClassClass();
Template, Value: MbElementDependentTemplateClass;
ObjKey, DictKey, ElemKey: uinteger;
Begin
MB := Params.Metabase;
Obj := MB.ItemById["DICT1"];
Dictionary := MB.ItemById["DICT"];
RdsDictIns := Dictionary.Open(Null) As IRdsDictionaryInstance;
Elements := RdsDictIns.Elements;
// Object settings:
Obj := Obj.EditDescriptor();
Obj.ElementDependenciesTrackingType := MbElementDependenciesTrackingType.mbeledeptratypDependecies;
Obj.ElementDependents;
Obj.SaveDescriptor();
/// Settings:
DictKey := Dictionary.Key;
ObjKey := Obj.Key;
ElemKey := Elements.Element[1]; // for the first dictionary element
// Template:
DependTemplClassT.CreateByObject(ObjKey);
Template := DependTemplClassT As MbElementDependentTemplateClass;
Template.ElementKey := Elements.Element[4] As integer;
// Collection of dependencies:
Depends := Mb.ElementDependentsDatabase.@New();
Depends.Where := Template As MbElementDependentTemplateClass;
DependTemplClassV.Create(ObjKey, DictKey, ElemKey);
Value := DependTemplClassV As MbElementDependentTemplateClass;
Depends.Add(Value);
Depends.Database.Update(Depends);
System.Diagnostics.Debug.WriteLine("=== Object: " + Obj.Name + " ===");
System.Diagnostics.Debug.WriteLine("Track links to elements from other objects: ");
If Obj.TrackElementDependencies = True Then
System.Diagnostics.Debug.WriteLine(" - option is enabled");
Else
System.Diagnostics.Debug.WriteLine(" - option is disabled");
End If;
System.Diagnostics.Debug.WriteLine("=== Dictionary: " + Dictionary.Name + " ===");
System.Diagnostics.Debug.WriteLine("Track links to elements from other objects: ");
If Dictionary.TrackElementDependents = True Then
System.Diagnostics.Debug.WriteLine(" - option is enabled");
Else
System.Diagnostics.Debug.WriteLine(" - option is disabled");
End If;
End Sub;
See also: