Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2020-10

initialization order of units

5 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Pascal Riekenberg

Have there been any changes to the initialization order of units in the last 6 month? I have a complex project with multiple units with initialization section. And now one of those units does not get initialized before it is used by the initialization part of an other unit. This worked at the beginning of the year!

I tried to move this unit up in all units where it is used. Without luck! It's the first unit after Forms in the program.

Any hints?

fpc version: trunk

Pascal

Reply by email

Jonas Maebe
to Pascal Riekenberg
Pascal Riekenberg wrote 7 lines
Have there been any changes to the initialization order of units in the last 6 month? I have a complex project with multiple units with initialization section. And now one of those units does not get initialized before it is used by the initialization part of an other unit. This worked at the beginning of the year!

It might be caused the fix for
https://bugs.freepascal.org/view.php?id=32352. Keep in mind that if there are uses-cycles via the implementation section, the initialisation order of the involved units is undefined.

Jonas

Reply by email

Pascal Riekenberg
to Jonas Maebe
Show quoted text 16 lines
Jonas Maebe via fpc-devel hat am 22.10.2020 22:28 geschrieben: On 22/10/2020 21:35, Pascal Riekenberg via fpc-devel wrote: > Have there been any changes to the initialization order of units in the > last 6 month? > I have a complex project with multiple units with initialization > section. And now > one of those units does not get initialized before it is used by the > initialization part of > an other unit. This worked at the beginning of the year! It might be caused the fix for https://bugs.freepascal.org/view.php?id=32352. Keep in mind that if there are uses-cycles via the implementation section, the initialisation order of the involved units is undefined.

There it is again: my pet project: Why doesn't pascal allow circular unit references (at least for classes, like forwards)! I like pascal very much but this is the biggest annoyance! You always have to work around this (put multiple classes in one unit, create interface classes, ...). And now this:

I have such cycles, but it worked before.
I removed this cycles and it worked as expected.

Isn't there a way to force the order?

Why isn't it initialized first even if the unit is the first after Forms in the program?

If there are uses-cycles via the implementation section why doesn't fpc prioritize interface order?

Pascal

Reply by email

Florian Klämpfl
to Pascal Riekenberg
Pascal Riekenberg wrote 30 lines
> Jonas Maebe via fpc-devel hat am 22.10.2020 22:28 geschrieben: > > > On 22/10/2020 21:35, Pascal Riekenberg via fpc-devel wrote: >> Have there been any changes to the initialization order of units in the >> last 6 month? >> I have a complex project with multiple units with initialization >> section. And now >> one of those units does not get initialized before it is used by the >> initialization part of >> an other unit. This worked at the beginning of the year! > > It might be caused the fix for > https://bugs.freepascal.org/view.php?id=32352. Keep in mind that if > there are uses-cycles via the implementation section, the initialisation > order of the involved units is undefined. There it is again: my pet project: Why doesn't pascal allow circular unit references (at least for classes, like forwards)! I like pascal very much but this is the biggest annoyance! You always have to work around this (put multiple classes in one unit, create interface classes, ...). And now this: I have such cycles, but it worked before. I removed this cycles and it worked as expected. Isn't there a way to force the order? Why isn't it initialized first even if the unit is the first after Forms in the program? If there are uses-cycles via the implementation section why doesn't fpc prioritize interface order?

Basically because of this:

https://bugs.freepascal.org/view.php?id=32352#c118712

Reply by email

J. Gareth Moreton
to Florian Klämpfl

This is just my personal opinion, but I do think that using "initialization" is risky if it uses anything outside of the unit, and hence you should minimise any inter-dependencies.  If I had to suggest a concrete workaround, it would be a initialisation routine that you call manually or as part of an object constructor, although it ends up requiring a bit more work for those who use the unit.

Sorry I can't be of much more help.

Gareth aka. Kit

Florian Klämpfl wrote 44 lines
Am 22.10.20 um 23:04 schrieb Pascal Riekenberg via fpc-devel: >> Jonas Maebe via fpc-devel hat am >> 22.10.2020 22:28 geschrieben: >> >>   On 22/10/2020 21:35, Pascal Riekenberg via fpc-devel wrote: >>> Have there been any changes to the initialization order of units in >>> the >>> last 6 month? >>> I have a complex project with multiple units with initialization >>> section. And now >>> one of those units does not get initialized before it is used by the >>> initialization part of >>> an other unit. This worked at the beginning of the year! >> >> It might be caused the fix for >> https://bugs.freepascal.org/view.php?id=32352. Keep in mind that if >> there are uses-cycles via the implementation section, the >> initialisation >> order of the involved units is undefined. > > There it is again: my pet project: Why doesn't pascal allow circular > unit references (at least for classes, like forwards)! > I like pascal very much but this is the biggest annoyance! > You always have to work around this (put multiple classes in one > unit, create interface classes, ...). And now this: > > I have such cycles, but it worked before. > I removed this cycles and it worked as expected. > > Isn't there a way to force the order? > > Why isn't it initialized first even if the unit is the first after > Forms in the program? > > If there are uses-cycles via the implementation section why doesn't > fpc prioritize interface order? Basically because of this: https://bugs.freepascal.org/view.php?id=32352#c118712 _______________________________________________ fpc-devel maillist  -  https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus

Reply by email