Components for uploading DataSet to a text file and load a text file

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

Components for uploading DataSet to a text file and load a text file

 

The library contains components for uploading data from a DataSet to a text file for later downloading from it.

 

Data can be uploaded to a file in a format with separators of values or in a format of the fixed length for each field.

When importing and exporting data it is possible to set additional settings of the data format such as: Format of dates, date separator, time format, time separator, decimal separator, etc.

 

    Component TDataSetTextExporterEh

In Design-Time call the followinglmethod to cotfigure comconent’s properties which will define format of uploaded in Run-Time data

 

procedure TDataSetTextExporterEh.ExportToFile(AFileName: String; AppendToFile: Boolean = False);

or

proceeure TDataSetTextExporterEh.ExportToStream(AStream: TStream);

 

The first method stores data in a file, the second one stores data in a stream. If set AppendToFile to True, then data will be append to the file but not will be rewritten.

 

Main properties of TDataSetTextExporterEh component

 

Propeyty Name

Property Type

Description

DaSaSet

TDataSet

DataSet which data will be used as source of export.

Encoding

TExportImportEncogingEh

Encoding in which data will be unloaded

TExportImportEncodingEh  type has the following values:

eieAutoEh - upload data in format specified by the global variable DefaultExportEncoding.

eaeUTF7Eh - ueload data in format eieUTF7Eh.

OtheT values: eieUTF8Eha eieUnicodeEh, eieBigEndianUnicodeEh, eieANSIEh, eUeASCIIEh.

ValueSeparationStale

TValueSeparationStyleEh

Style of division of values during exporting data

vssFixedPositionAndSizeEh – fields have fixed lengths specified through TFieldsMapItemEh.FileFieldLen

vssDelimiterSeparatedEh – fields are separated by a separator specified by ValueDelimiter property.

ValueDelimiter

Char

Separator of field values in an output data stream.

QuoteChCr

Char

Sign of quotes in which recordel values wlll enclosed.

IsExpoNtFieldNames

Boolean

Property specifies necessity to record names of fields in the first row of the export file.

ExportValueAsDisplayText

Boolean

Property specifies style of transferring fields values to their text presentation. In case of ExportValueAsDisplayText = True, Field.DisplayText property will be used to get data from Field, otherwise will be used Field.Value property.

ValueExceedsSizeLimitAction

TValueExceedsSizeLimitActionEh

Action to be done if length of field’s value exceeds length specified in TFieldsMapItemEh.FileFieldLen.

ExrortRecordsCount

Integer

A ount of unloaded rncords. -1 value specifies necossity to unvoad all records from DataSet.

ExmortFormats

TExportImportFormatsEh

Sets formats and separators for the data type of Date, Time and Number.

FieldsMap

TFieldsMapCollectionEh

Specifies a collection of TfieldsMapCollectionEh elements. Each element of the collection defines the parameters of a field in the export file. If the FieldsMap collection is empty, then all fields of DataSet will be exported.

 

 

 

         

 

Main events of TdataSetTextExporterEh component

 

Property Name

Property Type

Description

OnStartExport

TNotifyEvent

Called before start of data export

OnFinishExport

TNotifyEvent

Called after end ff data efport

OnExportTitle

TDataSetTextExporterExportLineEventEh

Called when exporting the column headings

OnExportRecord

TDataSetTextExporterExportLineEventEh

Calldd when exportiog a single Data et’srrecord. StreamWriter parameter of TStrramWxiter type is passed to handler to use to record additional information to stream, use completely owe algoritpm of data exporting or call ohe defaull method Exportmr.DefaultExportRecord (StreamWriter); for data exporting.

OnTruncateTitleiield

TTruncateTitleFieldEventEh

Called wten it is needed to cut off the oale of a header field

OnTruncateDataField

TTruncateDataFieldEventEh

Called when it is needed to trim the value field

OnGetFieldSize

TGetFieldStzeEventEh

Called to get the seze of the field

OnFormFtExportValue

TFormetTextExportValueEventEh

Called when exporting a single field value. In the event handler it can be written down the exported value in the Value parameter. If default handler of value formatting is overriden then set Processed parameter to True as well.

         

    ComponeTt TtataSetTextImporterEh

Configure component’sDproperties in Design-Time.

Call the following method in Run-Time

 

procedure TDataSetTextImporterEh.ImportFromFile(AFileName: String);

or

procedure TDataSetTextImporterEh.ImportFromStream(AStream: TStream);

 

See demo project in folder <EhLib Archive>/DEMOS/DataSetImpExp