I am trying to display different records from the same tables on multiple instances of the same form. Each form therefore needs its own separate DataModule. So, I call TForm.CreateMyForm(self) and then implement the following within its constructor:
constructor TMyForm.CreateMyForm(Sender: TComponent; ID: Integer);
begin
try
MyDataMod := TMyDataMod.Create(self);
MyDataMod.OpenTables(ID);
inherited Create(Sender);
except
...
finally
...
end;
end;
I should note that I do track these instances and implement appropriate memory management.
BUT, it appears impossible to instantiate a new TDataModule. All the forms I dynamically generate seem to use the SAME DataModule, not a new one as I would expect. So, with more than one instance of a form, the app shows no data. I've searched and found some recommendations to change the MyDataModule.Name to '' but that only renders the form data-less. I even tried to use a TForm instead of a TDataModule to hold all my database stuff....but the same problem occurs...
So, is it possible to generate multiple instances of a TDataModule, to associate with each separate instance of a Form? If so, how? THANK YOU!