FilterIf: IExpression;
The FilterIf property returns condition of loading of records from data provider.
To provide correct work of the condition, set the IDtObject.Metabase property.
Executing the example requires the D:\res_export.txt file in the file system.
Contents of the file res_export.txt
Add links to the Dal, Dt, Metabase system assemblies.
Sub UserProc;
Var
Mb: IMetabase;
TextProvider: IDtTextProvider;
v: Array;
i: Integer;
Errors: IDtErrors;
Error: IDtError;
Begin
Mb := MetabaseClass.Active;
// Create an object for import from text file
TextProvider := New DtTextProvider.Create;
// Specify imported file
TextProvider.File := "D:\res_export.txt";
// Set import options
TextProvider.FormatType := DtTextFormatType.Delimited;
TextProvider.DelimitedColumnDelimiter := ";";
TextProvider.DelimitedTextQualifier := """";
TextProvider.Encoding := "WIN";
// Specify that imported file contains headers
TextProvider.RangeHasHeader := True;
// Read fields from imported file
TextProvider.FieldsFromFile;
// Find the Value field and specify that it has real type
TextProvider.Fields.FindByName("Value").DataType := DbDataType.Float;
// Set repository
TextProvider.Metabase := Mb;
// Set filtering condition
TextProvider.FilterIf.AsString := "{VALUE} > 2.8";
// Set error handling parameters
Errors := TextProvider.FetchErrors;
Errors.MaxErrors := -1;
Errors.MaxItems := -1;
// Open data source
TextProvider.Open;
// Load records and display them in the console window
While Not TextProvider.Eof Do
TextProvider.Fetch(v);
For i := 0 To v.Length - 1 Do
Debug.Write(v[i] + " ");
End For;
Debug.WriteLine("");
End While;
// Display information about import in the console window
Debug.WriteLine("Number of read rows (ignoring filter): " + TextProvider.ReadingRowsTotalCount.ToString);
Debug.WriteLine("Number of read rows (with filter): " + TextProvider.ReadingRowsCount.ToString);
// Display information about import errors
For i := 0 To Errors.Count - 1 Do
Error := Errors.Item(i);
Debug.WriteLine("Number of row with error: " + Error.Row.ToString);
Debug.WriteLine("Error: " + Error.Message)
End For;
// Close data source
TextProvider.Close;
End Sub UserProc;
After executing the example import from the D:\res_export.txt file is set up. The rows, in which value of the Value attribute is greater than 2.8, are imported. Information about import and import errors is output to the console window.
See also: