IDtObjectCreator.CreateDtObjectFromFile

Syntax

CreateDtObjectFromFile(FileName: String): IDtObject;

Parameters

FileName. Path and name of the file based on which the data provider must be created.

Description

The CreateDtObjectFromFile method creates a provider linked to the selected file.

Comments

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:

Example

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:

IDtObjectCreator