Search code examples
delphidatamodule

DataModule created before main form


Some database application developers prefer to create a data module before main form by editing the project source file like this

begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TDM, DM);
  Application.CreateForm(TMainForm, MainForm);
{...}
  Application.Run;
end.

The question is - why? What are pros and contras?


Solution

  • The obvious reason would be if the main form needs the Data Module for its setup. For example, if there's something in there that the main form references in its OnCreate, then of course the data module would have to be ready first.

    Otherwise, it doesn't really matter.