Create modal forms using nil – not Application or Self

When creating a modal form (i.e. using Showmodal) and then freeing it within the same procedure, it is best to create it using nil (such as Form:=TForm.Create(nil);) instead of using "Application" or "Self" (e.g. Form:=TForm.Create(Application);).

The problem with using Application or Self as the parent is that that it takes longer for your form to be displayed. This is caused by a notification method that is sent to every component and form owned or indirectly owned by the Application or the parent form when using "Self". If your application consists of many forms with many components and the parent is set to Application or you use Self and the parent form you're creating has many controls, the notification delay can be significant.
Passing nil as the owner instead of Application or Self will cause the form to appear sooner, and should not affect your program unless you happen to be using the Parent property of the form in your code.


< Back to list of hints and warnings