This Is How To Easily Process CSV Data Using FireDAC
CSV is an abbreviation for a Comma-Separated Value file that enables data to be saved in a loosely-structured text form. Because of its simple format, it is very easy to process the data inside the file and extremely portable too. The great thing about the CSV files is that they are compatible with almost any text editor as well as a large number of popular applications such as Microsoft Excel or Google Sheets, making them easy to create, share, and edit. A CSV file is a type of delimited text file because it typically utilizes a comma to separate values. Some files also use the TAB character (ASCII 8) instead of the comma to break up the fields. Files which use the TAB character in this way are often referred to as Tab-Separated Value TSV files. Fields can also be optionally ‘wrapped’ with double-quotes (“), especially if they might contain commas. However these CSV/TSV files are formatted we can easily read them using Delphi and the FireDAC components. Are CSV files used in professional businesses? The short answer is: yes. CSV files are so easy to use that almost every type of business makes use of them to transfer and exchange data. One example is updating or downloading product data from an application. For example, you can bulk import new products to your system or store web app. Because of its simplicity and straightforward format, millions of developers utilize CSV files. Often, tech savvy Business owners can quickly read, comprehend, and edit the information without specialist help. Here is an example of a CSV file: How to use CSV files in Delphi applications? Embarcadero RAD Studio provides Delphi & C++ Builder development environment, and they have FireDAC components. FireDAC provides a common API for accessing different database back-ends with high performance. Moreover, FireDAC components provide easy access to CSV files. It abstracts the data into tables, views and stored procedures can be used to process CSV file. In this demonstration, we will utilize TFDBatchMove. We can use the TFDBatchMove component to move data between plain text files and tables using datasets. This demo project shows how to utilize the TFDBatchMove component to move information between different sources. Plain text to Table Table to Text Table to Plain text The TFDBatchMove implements the needed engine to move data between different types of data, and it uses reader and writer components. Here are some of the standard reader and writer components: TFDBatchMoveTextReader – Reader for plain text file TFDBatchMoveDataSetWriter – Writer for TDataSet TFDBatchMoveDataSetReader – Reader for TDataSet TFDBatchMoveTextWriter – Writer for plain text file These components define the data source reader using plain text files. So after establishing a stream from where to move the data using TFDBatchMove, it is easy to work with files. In this code, you can see that there are custom properties adjusted according to the plain text file format. So, the TFDBatchMove can automatically manage the reader instance. <br /> // Text file -> DB table<br /> procedure TfrmMain.btnASCToTabMoveClick(Sender: TObject);<br /> begin<br /> CloseQueries;</p> <p> // Create text reader and set FDBatchMode as owner. Then<br /> // FDBatchMove will automatically manage the reader instance.<br /> with TFDBatchMoveTextReader.Create(FDBatchMove) do<br /> begin<br /> // Set text data file name<br /> FileName := ExtractFilePath(Application.ExeName) + ‘Data.csv’;<br /> // Setup […]
