Delphi Programming

Sample data module

DataModule - module for non-visual VCL components, mostly location for data access components and relevant code. Generally, a TDataModule is similar to a TForm. Developer can place and manipulate components, but only non-visual. Mostly is used for the following purposes:

  • Centralized data manipulation
Centralized handling of data access components, like: database connection (TSQLConnection, TADOCOnnection, TIBDatabase, etc.) or data sets (TSQLDataset, TADODataset, …). Centralized data module is convenient especially when an application has multiple forms that share the same data or the same connection. Data module can be used for centralized validation for data business rules. Preventing invalid data begin entered into a database.
  • Centralized actions and application code
Data module can hold sets of actions inside relevant container (like TActionManager) or other bussines actions and rules. Also TDataModule class can contain shared methods, fields and properties used in many other modules. Data modules make code maintenance easier.
  • Web module
A TWebModule is descendant of TDataMoule and is used for designing web application.