The block initialization section is usually not a speed issue (unless you have some database related data).
Which can slow down loading TForm from resources.
It is always better to create TForm on the fly only when it is necessary: โโ- Go to the "Project" menu, then select "Options", then the "Forms" tab. - Put all optional forms from the left list to the right โavailableโ list. - Create forms on demand using some code.
The unit remains unchanged:
type TOneForm = class(TForm) .... end; var OneForm: TOneForm;
But you can use the following code to create the form on request:
Instead of the former
OneForm.ShowModal;
uses this kind of code
if OneForm=nil then OneForm := TOneForm.Create(Application); OneForm.ShowModal;
You will find downloading the application much faster.
Note: I just read that the problem was before loading the form. Thus, the above trick will not work for this particular problem. I hold the answer, because it may be useful to others. Next time I will read better. :(
In all cases, having a lot of code launched from initialization is not a good design. It sounds like a lot of global objects or variables ... refactoring may make sense here ... :)
Arnaud bouchez
source share