Building a Windows VCL dbExpress Database Application

From RAD Studio
Jump to: navigation, search

Go Up to How To Build Windows VCL Applications


The following procedure describes how to build a dbExpress database application.

Building a Windows VCL dbExpress application consists of the following major steps:

  1. Set up the database connection.
  2. Set up the unidirectional dataset.
  3. Set up the data provider, client dataset, and data source.
  4. Connect a DataGrid to the connection components.
  5. Run the application.

To add a dbExpress connection component:

  1. Choose either File > New > Windows VCL Application - Delphi or File > New > Windows VCL Application - C++Builder .
  2. From the dbExpress page of the Tool Palette, place a TSQLConnection component on the form.
  3. Click the TSQLConnection component from the form and set its ConnectionName property to IBConnection, in the Object Inspector. This setting automatically does the following:
    • Sets the Driver property to INTERBASE.
    • Assigns a UserName (sysdba) and a PassWord (masterkey) to provide secured access to the database.
  4. You need to specify the path to your InterBase database file (your .gdb file) in the Database field.
Note: InterBase 2020, which is part of the RAD Studio product installation, introduces new, strong user password encryption. Because of this change, using RAD Studio Athens with an older version of InterBase might lead to the following error message: "Unrecognized database parameter block."
To solve this problem, update your InterBase client with the client from InterBase 2020 because by default, InterBase 2020 installs a new admin.ib (user authorization database) with strong user password encryption. Also, you can solve this problem by changing the file admin.ib with another version from an older version of Interbase (while the Interbase server is stopped). If you encounter other issues with IBConnection, see the Migration Issues for InterBase section of the Interbase Readme. See also InterBase page for more information.


To set up the unidirectional dataset:

  1. In the Tool Palette on the dbExpress page, place a TSQLDataSet component on the form.
  2. In the Object Inspector, select the SQLConnection property drop-down list. Set it to the name of your TSQLConnection component.
  3. Set the CommandText property to an SQL command, for example, Select * from Table_Name. You are prompted to log in. Use the masterkey password. For the SQL command, you can either type a Select statement in the Object Inspector or click the ellipsis at the right of CommandText to display the CommandText Editor where you can build your own query statement.
Tip: If you need additional help while using the CommandText Editor, click the Help button.
  1. In the Object Inspector, set the Active property to True to open the dataset.

To add the provider:

  1. In the Tool Palette on the Data Access page, place a TDataSetProvider component on the form.
  2. In the Object Inspector, select the DataSet property drop-down list. Set it to the name of your TSQLConnection component.

To add client dataset:

  1. In the Tool Palette on the Data Access page, place a TClientDataSet component on the form.
  2. In the Object Inspector, select the ProviderName drop-down. Set it to the name of your TDataSetProvider component.
  3. Set the Active property to True to allow data to be passed to your application. A data source connects the client dataset with data-aware controls. Each data-aware control must be associated with a data source component to have data to display and manipulate. Similarly, all datasets must be associated with a data source component for their data to be displayed and manipulated in data-aware controls on the form.

To add the data source:

  1. In the Tool Palette on the Data Access page, place a TDataSource component on the form.
  2. In the Object Inspector, select the DataSet property drop-down. Set it to the name of your TClientDataSet component.

To connect a DataGrid to the DataSet:

  1. In the Tool Palette on the Data Controls page, place a TDBGrid component on the form.
  2. In the Object Inspector, select the DataSource property drop-down. Set the data source to the name of your TDataSource component.
  3. Choose Run > Run . You are prompted to enter a password. Enter masterkey. If you enter an incorrect password or no password, the debugger throws an exception. The application compiles and displays a VCL form with a DBGrid.


The connections between the different components follow this diagram:

Diagram db.jpg


See Also