IDtProvider.CalcFieldsErrors

Syntax

CalcFieldsErrors: IDtCalcFieldErrors;

Description

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

Comments

Errors can be obtained only after calling one of the following methods: IDtProvider.Fetch, IDtProvider.FetchRows.

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
    DTProvider: IDtTextProvider;
    Errors: IDtCalcFieldErrors;
    Error: IDtCalcFieldError;
    fields: IdtFieldDefinitions;
    field: IdtFieldDefinition;
    i: Integer;
    v: Array;
    data: Variant;
    Text: String;
Begin
    // Create a data provider
    DTProvider := New DtTextProvider.Create;
    // Set basic parameters of data provider
    DTProvider.FormatType := DtTextFormatType.Delimited;
    DTProvider.RangeHasHeader := True;
    DTProvider.AutoFillFieldsMode := DtAutoFillFieldsMode.DataRow;
    DTProvider.TypeGuessRows := 10;
    DTProvider.Metabase := MetabaseClass.Active;
    DTProvider.DelimitedColumnDelimiter := ";";
    DTProvider.Encoding := "WIN";
    DTProvider.DelimitedTextQualifier := """";

    // Specify the file, from which data will be taken
    DtProvider.File := "c:\Import Text.txt";
    // Get data provider fields from file
    DTProvider.FieldsFromFile;
    fields := DTProvider.Fields;
    // Specify data type for field with the 1 index from data provider
    fields.Item(1).DataType := DbDataType.Integer;
    // Add a new calculated field to data provider
    field := fields.Add;
    field.Name := "CalcField";
    field.DataType := DbDataType.Integer;
    // Set expression for calculation of field value
    field.Expression.AsString := fields.Item(1).Name + "+6";
    // Set parameters for handling errors occurred during calculation of calculated fields
    Errors := DtProvider.CalcFieldsErrors;
    Errors.MaxErrors := -1;
    Errors.MaxItems := -1;
    // Open data provider
    DTProvider.Open;

    // Display field names in the console window
    Text := "";
    For i := 0 To fields.Count - 1 Do
        field := fields.Item(i);
        Text := Text + (field.Name + "; ");
    End For;
    Debug.WriteLine(Text);
    // Display field values in the console window
    While Not DTProvider.Eof Do
        DTProvider.Fetch(v);
        Text := "";
        For i := 0 To v.Length - 1 Do
            data := v[i];
            Text := Text + (data + " ");
        End For;
        Debug.WriteLine(Text);
    End While;
    // Close data provider
    DTProvider.Close;
    // Display errors in the console window
    For Each Error In Errors Do
        Debug.WriteLine("In the row No." + Error.Row.ToString + " in the field " + Error.Field + " an error occurred");
        Debug.WriteLine("Error text: " + Error.Message);
    End For;
End Sub UserProc;

As a result of executing the example data will be loaded from the c:\Import Textt.txt file. The calculated field with the following expression will be created: value of the field with the 1 index from the data source will be increased by six. The results will be displayed to the console. If on formula calculation there are any errors, it will be displayed to the console.

See also:

IDtProvider