IRdsLoaderBindings.AddByAttribute

Syntax

AddByAttribute(Attribute: IRdsAttribute): IRdsBaseBinding;

Parameters

Attribute. Dictionary attribute, for which a binding is created.

Description

The AddByAttribute method creates a binding for a specified attribute.

Comments

Binding type is set according to the attribute type. Basic properties can be defined for the binding, it can be cast to the required type, and set specific properties. The following types of binding are available:

Example

Executing the example requires that the repository contains a table with the T_Dictionary identifier and an MDM dictionary with the Dict_1 identifier. It is assumed that table fields and dictionary attributes have matching identifiers.

Sub UserProc;
Var
    MB: IMetabase;
    TableSource: ITable;
    RdsDictionary: IRdsDictionary;
    RdsLoader: IMetaRdsLoader;
    Attrs: IRdsAttributes;
    Attr: IRdsAttribute;
    Fields: ITableFields;
    Field: ITableField;
    Bindings: IRdsLoaderBindings;
    Binding: IRdsBaseBinding;
Begin
    MB := MetabaseClass.Active;
    // Data source
    TableSource := MB.ItemById("T_Dictionary").Bind As ITable;
    // Updated dictionary
    RdsDictionary := MB.ItemById("Dict_1").Bind As IRdsDictionary;
    RdsLoader := New MetaRdsLoader.Create;
    RdsLoader.Dictionary := RdsDictionary;
    RdsLoader.TableSource := TableSource;
    //Create bindings
    Attrs := RdsDictionary.Attributes;
    Fields := TableSource.Fields;
    Bindings := RdsLoader.Bindings;
    For Each Attr In Attrs Do
        //In the table find a filed with the identifier,
        //that matches dictionary attribute identifier
        Field := Fields.FindById(Attr.Id);
        If Field <> Null Then
            Select Case Attr.PredefinedType
                Case RdsPredefinedAttribute.Key:
                    Binding := Bindings.KeyBinding;
                    Binding.Attribute := Attr;
                    Binding.Field := Field.Id;
                Case RdsPredefinedAttribute.Name:
                    Binding := Bindings.NameBinding;
                    Binding.Attribute := Attr;
                    Binding.Field := Field.Id;
                Case RdsPredefinedAttribute.Order:
                    Binding := Bindings.OrderBinding;
                    Binding.Attribute := Attr;
                    Binding.Field := Field.Id;
                Else
                    Binding := Bindings.AddByAttribute(Attr);
                    Binding.Field := Field.Id;
            End Select;
        End If;
    End For;
    //Update records
    RdsLoader.Load(UpdateLoadMode.InsertUpdate);
End Sub UserProc;

Executing the example initializes the object that is used to create MDM dictionaries and load data to them. The object settings contain a MDM dictionary to be updated, and bindings for all attributes are created. After this dictionary data is updated.

See also:

IRdsLoaderBindings