Skip to main content

Master-Detail Tutorial. Step 1: Connecting to Data

  • 2 minutes to read

This tutorial step explains how to create grid Table Views and bind them to different data sources.

  1. Create an empty application project.

  2. Create a database which will be connected to the tables. Place a TDatabase component on a form. Set its properties as follows:

In order to specify connection parameters for the database, double-click on the component. In the opened Database Editor dialog click the Defaults button to obtain a list of all parameters, as well as their default values. Set the PATH parameter to a string which defines a path to the directory where the FILMS, FILMSPERSONSSTAFF, FILMSSCREENS and PERSONS tables are located. Click the OK button to close the Database Editor dialog.

To connect the database to the tables, set its Connected property to True.

  1. Place a TTable component onto the form. This table will represent the FILMS table from the DemosDB database. Set its properties as follows:
  • DatabaseName to DemosDB

  • Name to tblFilms

  • TableName to FILMS.DB

  • Active to True. Note that the Active property must be set after all other properties are specified.

  1. Add a new TTable component on the form. Set its properties to the following values:
  • DatabaseName to DemosDB

  • Name to tblStaff

  • TableName to FILMSPERSONSSTAFF.DB

  • the Active property to True.

  1. Place another new TTable component on the form. Set its properties as follows:
  • DatabaseName to DemosDB

  • Name to tblFilmScreens

  • TableName to FILMSSCREENS.DB

  • Active to True.

  1. Place a further new TTable component on the form. Set its properties to the following values:
  • DatabaseName to DemosDB

  • Name to tblPersons

  • TableName to PERSONS.DB

  • Active to True.

  1. Place a TDataSource component on the form which will connect to the tblFilms dataset. Set the Name property to dsFilms and the DataSet property to tblFilms.

  1. Place another three TDataSource components to connect to the other tables. Specify their names as dsStaff, dsFilmScreens and dsPersons and set their DataSet properties to tblFilms, tblStaff, tblFilmScreens and tblPersons respectively.
See Also