Data modules simplify data access development in your applications. Data modules offer you a centralized design-time container for all your data access components. This enables you to modularize your code and separate the database access logic and business rules in your applications from the user interface logic in the application. You can also maintain control over the use of the data module by delivering only the .class files to application developers.
A data module is a specialized container for data access components. Once you define your DataSet components and their corresponding Column components in a data module, all frames that use the module have consistent access to the data sets and columns without requiring you to recreate them on every frame each time you need them. Data modules do not need to reside in the same directory or package as your project. They can be stored in a location for shared use among developers and applications.
The DataModule is an interface which declares the basic behavior of a data module. To work with this interface programmatically, implement it in your data module class and extend it by adding your data components.
To create a data module using the Data Module Wizard,
You'll notice that the code generated by the wizard for the data module class is slightly different than the code generated by other wizards. The getDataModule() method is defined as static public. The purpose of this method is to allow a single instance of this data module to be shared by multiple frames. The code generated for this method is:
static public DataModule1 getDataModule() {
if (myDM == null)
myDM = new DataModule1();
return myDM;
}
The code for this method
The data module class now contains all the necessary methods for your custom data module class, and a method stub for the jbInit() to which you add your data components and custom business logic.
Note: The property settings and business logic code you add to the components in the data model cannot be overridden in the application that uses the data model. If you have behavior that you do not want to enforce across all applications that use this data model, consider creating multiple data models that are appropriate for groups of applications or users.
To add code to the events of a component,
In your application,
DataModule1 dm1 = DataModule1.getDataModule();
DataModule1 dm1 = new DataModule1();
Click the Design tab to open the UI Designer; the instance of the data module appears in the Component Tree. Clicking the entry for the data module does not display its DataSet components nor its Column components. This is intentional to avoid modification of the business logic contained in the data module from outside.
When designing your application, you'll notice that the dataSet property of a UI Control includes all the DataSetView and StorageDataSet components that are included in your data module. You have access to them even though they are not listed separately in the Component Tree.
If you have a complex data model and /or business logic that you don't want another developer or user to manipulate, encapsulating it in a reusable component is an ideal way to provide access to the data but still enforce and control the business logic.