Creating Business Rules in a Data Module

From RAD Studio
Jump to: navigation, search

Go Up to Creating and Editing Standard Data Modules

Besides writing event handlers for the components in a data module, you can code methods directly in the unit file for a data module. These methods can be applied to the forms that use the data module as business rules. For example, you might write a procedure to perform month-, quarter-, or year-end bookkeeping. You might call the procedure from an event handler for a component in the data module.

The prototypes for the procedures and functions you write for a data module should appear in the module's type declaration:

type
  TCustomerData = class(TDataModule)
    Customers: TClientDataSet;
    Orders: TClientDataSet;
    // ...
  private
    { Private declarations }
  public
    { Public declarations }
    procedure LineItemsCalcFields(DataSet: TDataSet); { A procedure you add }
  end;
var
  CustomerData: TCustomerData;

The procedures and functions you write should follow in the implementation section of the code for the module.

See Also