I am using Delphi6
and have a data module with an ADO
DataSet
which is used by two forms, formA and FormB. Each form has a Datas
The simplest way to achieve what you want is to create an instance of the data module for each form, and pass it to the form so it can be freed when the form is closed:
var
Data: TDataModule;
begin
Data := T.Create(Self);
try
Form := T.Create(Self);
Form.DataModule := Data;
Data.Name := '';
except
Data.Free;
raise;
end;
Form.Show;
end;
Setting the DataModule's Name to an empty string is done to ensure that the VCL's logic for hooking up data aware controls to their datasource/dataset is done using the newly created instance, instead of the first ever instance.
In the Form's OnClose handler (or its destructor) make sure to free the data module.