A Delphi project with many divisions requires a lot of effort

I have a dpr with 290+ units.

Compiled exe is 50 MB.

The dpr code now looks like this:

begin ShowMessage('Before Initialize'); Application.Initialize; 

When I double-click on the built-in exe, I notice that 8 seconds have passed before I see "Before Initialize". Is it because of the large exe size? Or is there a way to minimize this time?

+6
performance delphi
source share
5 answers

Depending on your question, this could be anything.

The only advice I can give you is to measure:
Record the time stamps of each input / output in all initialization sections of your device.

Based on one of your comments (which you should add to your question as it describes in more detail):

WindowsCodecs.dll is initialized by one of your blocks, possibly converting one or more images from one format to another.
You must delay the conversion until the result of this conversion is needed.

- Jeroen

+4
source share

Before use. The initialization of each initialization section of each unit is performed. You may have code that takes time.

The number of units is not a problem. I have a project with 1100 + units, exe - 35 MB, and it starts instantly.

If you start with a network drive or a really slow drive, you may experience slowdowns.

+17
source share

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 ... :)

+1
source share

You already know that if you have many forms, try moving the forms from the "automatically create" list, and then adding code to create the forms when they are needed, but you see this problem before you can even create the form. So, as others have said, initialization problems are a problem.

Jeroen blog pointed me to a great resource for debugging this:

http://wiert.wordpress.com/2010/07/21/delphi-great-post-by-malcolm-groves-about-debugging-initialization-and-finalization-sections/

He pointed to Malcolm Groves:

http://www.malcolmgroves.com/blog/?p=649

+1
source share

There are many good suggestions in this matter .

You must absolutely make sure that you do not create things at startup that you do not need immediately. This is usually the biggest delay in launching projects with a lot of forms.

In your case, it sounds like a lot of initialization code is running.

+1
source share

All Articles