After the first FireDAC tip covering installation, let me start looking into actual development. FireDAC offers ready to use TDataSet descendant classes, like TADQuery, TADMemTable, TADStoredProc, and TADTable. They tend to have properties very similar to the corresponding BDE classes and the TClientDataSet. There are some more differences with the dbExpress datasets.

The underlying architecture, however, is more similar to recent versions of dbExpress and with ADO.NET, with data access classes representing commands and record sets. But this is a more advanced topic, good for a future tip.

Let's start by building a simple VCL application (FireMonkey one will be similar, of course, and I’ll build it next). The minimum set of components you need is:

  • The ADConnection component with minimal database configuration
  • An ADQuery component hooked with the connection (it connects automatically as you drop it in a designer with a connection). The query has a SQL text string list property, as in the BDE. As an alternative you can use an ADTable component
  • A DataSource component connected with the query
  • The proper visual components, in the simplest scenario a DBGrid control.

The minimal steps to have a running application are:

  • In the connection component pick a value for the DriverName property, like “IB” for InterBase
  • In the Params property enter the database file name, for example: “Database=C:\Embarcadero\InterBase\examples\database\employee.gdb” and add username and password
  • Eventually disable the LoginPrompt property, and try to connect (Connected = True)
  • Set the Connection property of the ADQuery component to the connection, if not already done
  • Edit the SQL string list property with the SQL text like “select * from Employee”
  • Activate the dataset
  • Connect the DataSource to the dataset and the grid to the data source, and you should see the data, as below:

To be able to deploy this application you need to add two more components, which effect is only to add references to the required units for the database driver and the hourglass:

  • The ADPhysIBDriverLink brings in the uADPhysIB unit and is the driver for connecting with the client library (no driver DLL to deploy like in dbExpress, as it is all in Delphi source code)
  • The ADGUIxWaitCursor component bring in the uADGUIxFORMSWait unit. In the component you can pick a Provider, which can be either “Forms” for VCL (the default, so nothing to change here), “Console”, or “FMX” for FireMonkey

In theory you could remove both components and the program will still run, given the referenced units, but it does make sense to keep the components around anyway. If you forget these components, you’ll get runtime exceptions indicating quite clearly you need to add those components to your application.

This is the running application (nothing special, I know):

 

This is all to get a first demo up and running. Given the source code is close to nothing (I added a line to open the query as the program starts), the relevant source code file is the DFM, with the component properties. The summary is listed below:

object Form7: TForm7
  OnCreate = FormCreate
  object DBGrid1: TDBGrid
    DataSource = DataSource1
  end
  object ADConnection1: TADConnection
    Params.Strings = ('Database=C:\Embarcadero\InterBase\
        examples\database\employee.gdb'
      'User_Name=SYSDBA'
      'Password=masterkey'
      'Protocol=TCPIP'
      'Server=localhost'
      'DriverID=IB')
    Connected = True
    LoginPrompt = False
  end
  object DataSource1: TDataSource
    DataSet = ADQuery2
  end
  object ADQuery2: TADQuery
    Active = True
    Connection = ADConnection1
    SQL.Strings = ('select * from employee')
  end
  object ADPhysIBDriverLink1: TADPhysIBDriverLink
  object ADGUIxWaitCursor1: TADGUIxWaitCursor
end

That’s all for a starting application. In the next tip we’ll explore some more features and FireDAC and of this program.