IDtConsumer.CalcFieldsErrors

Syntax

CalcFieldsErrors: IDtCalcFieldErrors;

Description

The CalcFieldsErrors property returns a collection of errors appeared on calculated fields calculation.

Comments

Errors can be received only after calling one of the following mwthods: IDtConsumer.Put, IDtConsumer.PutProvider, IDtConsumer.PutRow.

Example

Executing the example requires the c:\Import Text.txt file with data in the file system.

Add links to the Dal, Dt, Metabase system assemblies.

Contents of the c:\Import Text.txt file

Sub UserProc;
Var
    mb: Imetabase;
    DTConsumer: IDtTextConsumer;
    DTProviderWithData: IDtTextProvider;
    Errors: IDtCalcFieldErrors;
    Error: IDtCalcFieldError;
    FieldsIn, FieldsOut: IDtFieldDefinitions;
    FieldIn, FieldOut: IDtFieldDefinition;
    i: Integer;
Begin
    // Get current repository
    mb := MetabaseClass.Active;
    // Create text data consumer
    DTConsumer := New DtTextConsumer.Create;
    // Set consumer basic parameters
    DTConsumer.FormatType := DtTextFormatType.Delimited;
    DTConsumer.RowDelimiter := #13 + #10;
    DTConsumer.DelimitedColumnDelimiter := ";";

    DTConsumer.Encoding := "WIN";
    DTConsumer.DelimitedTextQualifier := """";
    DTConsumer.WriteHeader := True;
    DTConsumer.Metabase := mb;
    // Set file to which data will be loaded
    DTConsumer.File := "c:\Export Text.txt";
    // Create text data source
    DTProviderWithData := New DtTextProvider.Create;
    // Set source basic parameters
    DTProviderWithData.FormatType := DtTextFormatType.Delimited;
    DTProviderWithData.RowDelimiter := #13 + #10;
    DTProviderWithData.DelimitedColumnDelimiter := ";";
    DTProviderWithData.Encoding := "WIN";

    DTProviderWithData.DelimitedTextQualifier := """";
    DTProviderWithData.RangeHasHeader := True;
    DTProviderWithData.Metabase := mb;
    // Determine file from which data will be loaded
    DTProviderWithData.File := "c:\Import Text.txt";
    // Load source fields from file
    DTProviderWithData.FieldsFromFile;
    // Get source and consumer fields
    FieldsIn := DTConsumer.Fields;
    FieldsOut := DTProviderWithData.Fields;
    // Process each from obtained fields
    For Each FieldOut In FieldsOut Do

        // Specify data source field type
        FieldOut.DataType := DbDataType.Integer;
        // Add field to data consumer
        FieldIn := FieldsIn.Add;
        // Specify that basic parameters of added field in consumer
        // match with the corresponding field in data source
        FieldIn.DataDomain := FieldOut.DataDomain;
        FieldIn.DataType := FieldOut.DataType;
        FieldIn.Name := FieldOut.Name;
        FieldIn.Precision := FieldOut.Precision;
        FieldIn.Size := FieldOut.Size;
        // If field in data source is calculated, identical expression will be
        // used in data consumer 
        If FieldOut.IsCalculated Then
            FieldIn.Expression.AsString := FieldOut.Expression.AsString;
        End If;

    End For;
    // Set expression to calculate field with the 1 index in data consumer    
    FieldIn := FieldsIn.Item(1);
    // The field will be based on value of the field with the 1 index from data source
    FieldOut := FieldsOut.Item(1);
    FieldIn.Expression.AsString := FieldOut.Name + " + 2";
    // Open and clear data consumer
    DTConsumer.Open;
    DTConsumer.Clear;
    // Export values from the source to the consumer
    DTConsumer.PutProvider(DTProviderWithData);
    // Get errors occured on calculated fields calculation         
    Errors := DTConsumer.CalcFieldsErrors;

    // Display errors to the console
     If Errors.Count > 0 Then
        For i := 0 To Errors.Count Do
            Error := Errors.Item(i);
            Debug.WriteLine("In the row №" + Error.Row.ToString + " in field " + Error.Field + " the error occured");

            Debug.WriteLine("Error text: " + Error.Message);
        End For;
    End If;
    // Close data consumer
    DTConsumer.Close;
End Sub UserProc;

After executing the example data from the c:\Import Text.txt file will be loaded to the Export Text file. For source data the following formula will be applied: the filed value with the 1 index will be increased by two. If on formula calculation there are any errors, it will be displayed to the console.

See also:

IDtConsumer