3.8. Creating the Primary Modules

We will create two primary modules in our application: a product module and a customer module. Each primary dataset is displayed on a form by means of a TDBGrid grid and a toolbar with buttons. The business logic of working with the dataset will be located in a separate DataModule that contains a TDataSource data source, a TFDQuery dataset, and two TFDTransaction transactions, one read-only and one read/write.

As our model for creating datasets, we will create the Customer dataset on the dCustomers datamodule:

fbdevgd30 delphi 004

Figure 5. dCustomers datamodule

On tabbing to the Customers form, this is the initial view. The DataSource component is not visible on the form because it is located in the dCustomers datamodule.

fbdevgd30 delphi 005

Figure 6. Customers form, initial view

We have placed the TFDQuery component in the dCustomers datamodule and named it qryCustomers. This dataset will be referred to in the DataSet property of the DataSource data source in DCustomers. We specify the read-only transaction trRead in the Transaction property, the trWritetransaction in the UpdateTransaction property and, for the Connection property, the connection located in the main data module. We populate the SQL property with the following query:

  1. SELECT
  2. customer_id,
  3. name,
  4. address,
  5. zipcode,
  6. phone
  7. FROM
  8. customer
  9. ORDER BY name