CalcFieldsErrors: IDtCalcFieldErrors;
The CalcFieldsErrors property returns a collection of errors appeared on calculated fields calculation.
Errors can be received only after calling one of the following mwthods: IDtConsumer.Put, IDtConsumer.PutProvider, IDtConsumer.PutRow.
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 the current repository
Mb := MetabaseClass.Active;
// Create text data consumer
DTConsumer := New DtTextConsumer.Create;
// Set data consumer basic parameters
DTConsumer.FormatType := DtTextFormatType.Delimited;
DTConsumer.RowDelimiter := #13 + #10;
DTConsumer.DelimitedColumnDelimiter := ";";
DTConsumer.Encoding := "WIN";
DTConsumer.DelimitedTextQualifier := """";
DTConsumer.WriteHeader := True;
DTConsumer.Metabase := mb;
// Specify the file, to which data will be loaded
DTConsumer.File := "c:\Export Text.txt";
// Create text data provider
DTProviderWithData := New DtTextProvider.Create;
// Set data provider basic parameters
DTProviderWithData.FormatType := DtTextFormatType.Delimited;
DTProviderWithData.RowDelimiter := #13 + #10;
DTProviderWithData.DelimitedColumnDelimiter := ";";
DTProviderWithData.Encoding := "WIN";
DTProviderWithData.DelimitedTextQualifier := """";
DTProviderWithData.RangeHasHeader := True;
DTProviderWithData.Metabase := mb;
// Specify the file, from which data will be loaded
DTProviderWithData.File := "c:\Import Text.txt";
// Load data provider fields from file
DTProviderWithData.FieldsFromFile;
// Get data provider and data consumer fields
FieldsIn := DTConsumer.Fields;
FieldsOut := DTProviderWithData.Fields;
// Process each obtained field
For Each FieldOut In FieldsOut Do
// Specify provider field type
FieldOut.DataType := DbDataType.Integer;
// Add a field to data consumer
FieldIn := FieldsIn.Add;
// Specify that basic parameters of added field in data consumer
// will match with corresponding field in provider
FieldIn.DataDomain := FieldOut.DataDomain;
FieldIn.DataType := FieldOut.DataType;
FieldIn.Name := FieldOut.Name;
FieldIn.Precision := FieldOut.Precision;
FieldIn.Size := FieldOut.Size;
// If field in provider is calculated, the identical expression will
// will be used in consumer
If FieldOut.IsCalculated Then
FieldIn.Expression.AsString := FieldOut.Expression.AsString;
End If;
End For;
// Specify expression for calculation of field with the 1 index in data consumer
FieldIn := FieldsIn.Item(1);
// Expression will be based on value of the field with the 1 index from data provider
FieldOut := FieldsOut.Item(1);
FieldIn.Expression.AsString := FieldOut.Name + " + 2";
// Open and clear data consumer
DTConsumer.Open;
DTConsumer.Clear;
// Export values from data provider to data consumer
DTConsumer.PutProvider(DTProviderWithData);
// Get errors occurred during calculation of calculated fields
Errors := DTConsumer.CalcFieldsErrors;
// Display errors in the console window
If Errors.Count > 0 Then
For i := 0 To Errors.Count Do
Error := Errors.Item(i);
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 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: