CreateDtObjectFromFile(FileName: String): IDtObject;
FileName. Path and name of the file based on which the data provider must be created.
The CreateDtObjectFromFile method creates a provider linked to the selected file.
File extension and its contents are analyzed on executing the method. A provider of specific type and having certain parameters is created according to the analysis result. In the current version this method enables the user to create a provider based on the files of the following type:
XLS. Creates the provider described by the IDtExcelProvider interface.
XLSX. Creates the provider described by the IDtExcelProviderEx interface.
TXT. Creates the provider described by the IDtTextProvider interface.
CSV. Creates the provider described by the IDtTextProvider interface.
Executing the example requires a file named data.txt in the root directory of the disc C.
Sub UserProc;
Var
Creator: IDtObjectCreator;
Provider: IDtProvider;
Path: String = "C:\data.txt";
Fields: IDtFieldDefinitions;
Field: IDtFieldDefinition;
v: Array;
i: Integer;
Begin
Creator := New DtObjectCreator.Create;
Provider := Creator.CreateDtObjectFromFile(Path) As IDtProvider;
(Provider As IDtTextProvider).HeaderRow := 1;
Provider.FieldsFromFile;
Fields := Provider.Fields;
Debug.WriteLine(Fields);
For Each Field In Fields Do
Debug.Write(Field.Name + " ");
End For;
Debug.WriteLine("");
Debug.WriteLine(Values);
Provider.Open;
While Not Provider.Eof Do
Provider.Fetch(v);
For i := 0 To v.Length - 1 Do
Debug.Write(v[i] + " ");
End For;
Debug.WriteLine("");
End While;
Provider.Close;
End Sub UserProc;
The new provider linked to the data.txt file is created on executing the example. Fields names and values received from the file are displayed in the development environment output.
See also: