FieldsFromFile;
The FieldsFromFile method reads fields list from the source file.
It is used for text or Xml data sources.
NOTE. The method is activated automatically with opening text or Xml data provider .
Executing the example requires the Data.txt file in the disk C root directory.
Sub UserProc;
Var
TextProvider: IDtTextProvider;
Fields: IDtFieldDefinitions;
Field: IDtFieldDefinition;
v: Array;
i: Integer;
Begin
TextProvider := New DtTextProvider.Create;
TextProvider.File := "c:\Data.txt";
TextProvider.RangeHasHeader := True;
TextProvider.RowDelimiter := #13 + #10; //Carriage return + row transfer
TextProvider.DelimitedColumnDelimiter := #9; //Tab button
TextProvider.FieldsFromFile;
Fields := TextProvider.Fields;
For Each Field In Fields Do
Debug.Write(Field.Name + " ");
End For;
Debug.WriteLine("");
TextProvider.Open;
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;
TextProvider.Close;
End Sub UserProc;
After executing the example a new data source, that imports data from text file, is created. During import the Carriage return+Row transfer combination is used as a row delimiter, and Tabulation symbol - as a field delimiter. Before provider opening fields names from his first row are read and displayed in the console. Then all entries values are read and displayed in the development environment console.
See also: