Database Tutorial - part 2
Structure of the tables
Members.dbf contains the details of each club member. Its records (table rows)
have the following fields (table columns):
Guitars.dbf has the following fields:
Each record of Members.dbf is related to one or more records of Guitars.dbf, by means of the fields ID and MemberID, and a related index file (specifying the order of the records). The relation works like this:
Table 1 -> MasterField -> Table 2 -> Index file
Members.dbf -> ID -> Guitars.dbf ->
Guitars.mdx (index on MemberID)
Below is a snapshot of the application at runtime, with a relation set up between the two tables.
As you can see, President John is in the database with 4 guitars.
For this project, create a folder FPlaz\GuitarClub1, download GuitarClub1.zip and
unzip to this folder.
- Start Lazarus and open project GuitarClub1.
- Compile and run the application (press F9).
Note that at this stage, the lower grid shows all of the guitars.
- Stop the program.
- Now comes the magic: we'll set a relation between the two tables.
Select component dbfGuitars.
Set its property MasterSource to dsMembers.
Set MasterFields to ClubID.
Press F9 and navigate through the members (top grid). If all went well, now the bottom grid only shows the corresponding records.