Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
C++DatabaseDelphi

Learn How To Quickly Build A Key Value Store With SQLite In This Delphi FireDAC.SQLiteIniFile Sample App

Working with INI file becomes common in many Mobile, IoT, Desktop Applications. How about connecting SQLite database to Read/write to an INI file in Delphi/C++ Builder applications? This can be done easily with help of FireDAC.SQLiteIniFile Sample app.

FireDAC.SQLiteIniFile Sample uses FireDAC to connect to an SQLite database that emulates the structure and the operations of an INI File. This application reads and writes data to an INI file using a FireDAC database connection as its storage medium, instead of a plain text file.

You can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.

Components used in the Sample :

  • TFDQuery : To execute SQL queries, browse the result sets, and edit the result set records.
  • TFDPhysSQLiteDriverLink: To link the SQLite driver to an application and set it up. In general, it is enough to only include the FireDAC.Phys.SQLite unit into your application uses clause. The TFDPhySQLiteDriverLink component can be used to specify: The VendorHome – the SQLite installation root folder. The VendorLib – the name and the optional path to the SQLite client library.
  • TFDConnection : To establish a connection to a DBMS and to manage associated datasets.
  • TDatasource,TDBGrid,TDBNavigator to populate the values from IniFile.

Implementation Details:

  1. Run the sample application, and Click the Write to IniFile button and the program will create a database (IniFile.db) and fill it with data.
  2. The data from the database that was just created is displayed in a TDBGrid.
  3. You can manipulate the data with a TDBNavigator.
  4. Click the Read from IniFile button to display the data from the database in a TMemo and the image from the database in a TImage.
  • The project uses a TFDConnection to establish a connection with a database (IniFile.db), which will be used to write or read data.
  • To display the data from the database, the project uses a TFDQuery, a TDataSource, and a TFDPhysSQLiteDriverLink.The data will be displayed in a TDBGrid.You can navigate through the data with a TDBNavigator.
  • In the FireDAC.Phys.SQLiteIniFile.pas unit, several classes (TFDSQLiteIniFileDB and TFDSQLiteIniFile) are defined for interacting with the database.
    • Click the Write to IniFile button on the main form to create and initialize a TFDSQLiteIniFile instance (the oIniFile code variable) and to create the “IniFile.db” database. After this, a string (abcd…), an integer (123), a float (567.89), a date time (Now), and an image (the image from the data folder) are added to the database. The data that was just inserted in the database is displayed in a TDBGrid.Note: As shown by the TFDQuery SQL command, when “LENGTH(A.KEY_VALUE) > 32”TDBGrid will display “(blob)” instead of the actual value.
    • Click the Read from Inifile button on the main form to read from the database and display the string, the integer, the float, and the date time in a TMemo and the image will be displayed in a TImage.

Check out the full article in the DocWiki about the FireDAC SQLiteIniFile Sample.

<strong>FireDACSQLiteIniFile Sample App<strong>

Check out the full source code for the FireDAC.SQLLiteIniFile projects for Delphi and C++Builder over on GitHub.

See What's New in 12.2 Athens See What's New in 12.2 Athens Dev Days of Summer 2-24

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES