FireDAC-First App
FireDAC-First App
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 Ill 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.
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, youll get runtime exceptions indicating quite clearly you need to add those
components to your application.
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: