Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataModule created before main form [closed]

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?

like image 348
kludg Avatar asked Jan 14 '10 15:01

kludg


2 Answers

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.

like image 94
Mason Wheeler Avatar answered Sep 23 '22 00:09

Mason Wheeler


I agree with Mason's answer because it explains why people may do this. However, I believe this is a bad approach because it hides the dependency in code that is maintained by the IDE. In my opinion, the data module should be removed from the auto create list and it should be created in the main form's OnCreate method.

like image 21
Lawrence Barsanti Avatar answered Sep 24 '22 00:09

Lawrence Barsanti