[fpc-pascal] Is there a way to execute code after 'initialization' and before 'main', i. e. AddExitProc complement?

Sven Barth pascaldragon at googlemail.com
Tue Nov 28 23:32:36 CET 2017


Am 28.11.2017 20:04 schrieb "Роман via fpc-pascal" <
fpc-pascal at lists.freepascal.org>:

'Initialization' sections are executed in poorly predictable order, so I
want to partially order them according to some form of explicit
prioritization and execute before control flow enters main block (so I
won't need to run all that initialization by hand, neither I would be able
to forget to do that).


If unit A uses unit B in the interface section then unit B's initialization
section is always run before A's. For the implementation section the same
holds true if there isn't a cycle otherwise it depends on the unit load
order.

Like:

unit UnitA;
...
procedure Init;

initialization
  RegisterUnit('UnitA', @Init);
end;

unit UnitB;
...
procedure Init;

initialization
  RegisterUnit('UnitB', @Init, {priority} +1);
end;

...
procedure SortAndInitialize;
...

Can I run SortAndInitialize before 'main' without additional user actions?


No, you can't.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20171128/0dcead52/attachment.html>


More information about the fpc-pascal mailing list