Preparations
- If you haven't done so already, create a new folder \DelphiLand.
- If you haven't done so already, create directory SQLiteGeo
"under" \DelphiLand.
- Next, download sqlitegeo.zip and
unzip it to this directory.
A closer look
- Start Delphi and open sqlitegeo.dpr.
- In the the menu, select Project / Options...
- In the dialog that appears, select Delphi Compiler / Output directory
Clear this option and click OK.
That way, you avoid the need to enter a hardwired full path when setting FDConnection.Params.Database (see later).
- Open Delphi's File menu and click Save All.
-
The structure of the table Countries of database Geo.sqlite is as follows:
Field name |
Type |
name |
varchar(50) |
code |
varchar(10) |
population |
numeric |
currency |
varchar(25) |
curcode |
varchar(10) |
- In Design Mode, let's have a look at the components:
- FDConnection1 is a FireDac connection: it defines the connection parameters, establishes
a connection to a DBMS
(DataBase Management System) and manages the associated datasets.
- qCountries is a TDFQuery (FireDAC Query). Its property Connection is set to
FDConnection1 and its property SQL is set to
select * from countries
...meaning: select all fields from table countries
- dsCountries is a TDataSource, the interface between a dataset component
and data-aware controls. Its property DataSet is set to qCountries.
- gridCountries is a TDBGrid (DataBase Grid) that is used to visualize the contents
of the table Countries. Its property DataSource is set to dsCountries.
- DBNavigator1 is used to move through the data in the dataset and perform operations on the data,
such as inserting a record or posting a record. Its property DataSource is set to dsCountries.
- FDGUIxWaitCursor1 is a component that is needed for every FireDac application.
- Since most work has been done in Design Mode, the source code for this project is really minimal:
procedure TForm1.FormShow(Sender: TObject);
begin
FDConnection1.Close;
FDConnection1.Params.Clear;
FDConnection1.Params.Add('DriverID=SQLite');
FDConnection1.Params.Add('Database=geo.sqlite');
FDConnection1.Open;
qCountries.Open;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
qCountries.Close;
FDConnection1.Close;
end;
|
|