Add code before block initialization in Delphi

Is there a place where I can add code that will be executed before the device is initialized?

The reason I want to do this is that I need to change the DecimalSeparator, this needs to be done before some units are initialized. I put it in the project source before Application.Initialize, but it's too late.

As I see it, the only choice I have is to put it in the initialization of the block for which you need to change the DecimalSeparator, is this in this case?

Thanks in advance for any advice.

+4
source share
3 answers

The initialization order in Delphi is deterministic: units are initialized in the same order in which the compiler is compiled and completed in the reverse order. The compiler starts at the top of the DPR, uses the sentence and runs down, and for each device it finds, it does the same recursively: start from the beginning uses strong>, try to compile every used block that has not yet been compiled, then compile the current block. Therefore, if you can get your unit before any of them compiles, it will be initialized first.

If you want it to be executed first, make a new block, put the changes in the initialization block, and then make sure that it gets into DPR before any of the blocks that will depend on the changes. You might want to make it the first module, unless you have other “must have first” units, such as replacement memory managers.

+14
source

Put it in the initialization section of the first block in your uses project, so it will be executed before any other initialization code.

+3
source

A word of warning is here.

I have an application running on the registered user’s desktop, and in MIDDLE testing the application, the DecimalSeparator has changed for me, without restarting the application.

I used to install

 DecimalSeparator := '.'; 

once in the code of FormCreate (), but this is not enough. So now I install it every time before using the FormatFloat () function (used only in one place in my application).

I don’t know WHY this is happening, but there are probably some changes in the system parameter that reset char to ',' on my system.

The best way to avoid this is probably to set the decimal separator in your Windows configuration to. to avoid strange problems ...

+1
source

Source: https://habr.com/ru/post/1311146/


All Articles