IDtObject.KeepCalcFields

Syntax

KeepCalcFields: Boolean;

Description

The KeepCalcFields property determines whether the list of calculated fields is saved in case of data provider/data consumer change.

Comments

After data provider/consumer settings are defined, the Fields collection of fields will be filled in after calling the FieldsFromFile method. Proper calculated fields can also be added to this collection. By default, the KeepCalcFields property is set to False, and the list of fields in the Fields collection will be reset and loaded according to the structure of the new data provider/consumer in case of data provider/consumer change. The added calculated fields are also reset. To save the list of calculated fields, set the KeepCalcFields property to True.

Example

Executing the example requires two text files: 1.txt and 2.txt.

File text

Add links to the Dal, Dt, Metabase system assemblies.

Sub UserProc;
Var
    TextProvider: IDtTextProvider;
    Fields: IDtFieldDefinitions;
    Field: IDtFieldDefinition;
Begin
    // Set up provider
    TextProvider := New DtTextProvider.Create;
    TextProvider.File := "D:\Work\1.txt";
    TextProvider.Encoding := "WIN";
    TextProvider.DelimitedTextQualifier := '"';
    TextProvider.DelimitedColumnDelimiter := " ";
    TextProvider.RowDelimiter := #13 + #10;
    TextProvider.HeaderRow := 1;
    TextProvider.AutoFillFieldsMode := DtAutoFillFieldsMode.DataRow;
    TextProvider.TypeGuessRows := 5;
    // Load the list of fields from provider
    TextProvider.FieldsFromFile;
    TextProvider.Metabase := MetabaseClass.Active;
    Fields := TextProvider.Fields;
    // Add a calculated field
    Field := Fields.Add;
    Field.Name := "Calculate";
    Field.DataType := DbDataType.Float;
    Field.Expression.AsString := Fields.Item(2).Name + " * 10";
    // Number of fields before file replacement
    Debug.WriteLine("Fields before file replacement: " + TextProvider.Fields.Count.ToString);
    ShowFields(Fields);
    // Replace file
    TextProvider.KeepCalcFields := True;
    TextProvider.File := "D:\Work\2.txt";
    // Number of fields after file replacement
    Debug.WriteLine("Fields after file replacement: " + TextProvider.Fields.Count.ToString);
    ShowFields(Fields);
End Sub UserProc;

Sub ShowFields(Fields: IDtFieldDefinitions);
Var
    Field: IDtFieldDefinition;
Begin
    For Each Field In Fields Do
        Debug.Write(Field.Name + ' ');
    End For;
    Debug.WriteLine("");
End Sub ShowFields;

After executing the example a data provider is created that imports data from a text file. After the settings are defined, the list of fields is read from the 1.txt file, and one calculated field is added. The 2.txt file is set as a data provider, and the list of fields is loaded from the file again. The list of fields obtained from the first and the second files, taking into account the calculated field, will be displayed in the development environment console.

See also:

IDtObject