Free DataModule

<< Click to Display Table of Contents >>

Navigation:  Technology Overview > Forms and Modules > DataModules >

Free DataModule

A free datamodule is just a plain old datamodule.


unit _FreeDataModule;
  SysUtils, Classes;
  TFreeDataModule = class(TDataModule)
    { Private declarations }
    { Public declarations }
{$R *.dfm}


This kind of datamodule is used in the same way it was used in common VCL applications. The user is totally responsible of creating it when needed, and of releasing it as soon as is not needed anymore.


The reason for using this kind of datamodule comes from the fact that some non-visual components need a host/container (or it is easier to use them in that way). One good example is a reporting tool because it is usually dropped into a datamodule even if the user will only use it for exporting the report.


An additional reason for using datamodules is that no "business code" should be hosted in the presentation layer (TForm, TUniForm, any form). Using a free datamodule allows the developer to handle resources on-demand, keeping memory usage to a minimum.


Usage of free datamodule is demonstrated in FastReport and ReportBuilder demos which are available under ..\demos\desktop folder.