FireDAC.SQLiteIniFile Demo Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample uses FireDAC to connect to an SQLite database that emulates the structure and the operations of an INI File.

Location

You can find the SQLiteIniDemo project at:

Description

  • 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.
Note: The connection to the database does not require authentication.

How to Use the Sample

  1. Navigate to the location given above and open SQLiteIniDemo.dproj.
  2. Press F9 or choose Run > Run.
  3. Click the Write to IniFile button and the program will create a database (IniFile.db) and fill it with data.
  4. The data from the database that was just created is displayed in a TDBGrid.
  5. You can manipulate the data with a TDBNavigator.
  6. 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.

Files

File Contains

Demo\data\ winmacmachine.bmp

Contains the image that is diplayed in the TImage.

Demo\SQLiteIniDemo.dproj

Contains the project itself.

Demo\Unit1.dfm

Contains the code of the main form.

Demo\Unit1.pas

Contains the main form and the main code.

FireDAC.Phys.SQLiteIniFile.pas

Contains the code for the SQLiteIniFile class used for writting/reading to/from the IniFile.db.

ReadMe.txt

Contains information about FireDAC.Phys.SQLiteIniFile.pas.

Implementation

  • The project uses a TFDConnection to establish a connection with a database (IniFile.db), which will be used to write or read data.
  • The TFDQuery uses the following query:
 SELECT
   B.SECTION_NAME AS "Section::varchar(32)",
   A.KEY_NAME AS "Name::varchar(32)",
   CASE WHEN LENGTH(A.KEY_VALUE) <= 32 THEN A.KEY_VALUE
   ELSE '(blob)' END AS "Value::varchar(32)"
 FROM KEYS A
 LEFT JOIN SECTIONS B ON B.SECTION_ID = A.SECTION_ID
  • 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.

Uses

See Also

Tutorials

Personal tools
Assistance